Skip to content

Commit

Permalink
manifest.Schema1.LayerInfos(): fabricate a MediaType
Browse files Browse the repository at this point in the history
Schema 1 manifests don't track a MediaType for any of the layers that
they contain, but for the sake of blob info caches, make our
LayerInfos() method return the MediaType that's typical for layers in
Schema 2 manifests.

Signed-off-by: Nalin Dahyabhai <[email protected]>
  • Loading branch information
nalind committed Dec 1, 2020
1 parent 2767594 commit fd2134a
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 58 deletions.
30 changes: 18 additions & 12 deletions image/docker_schema1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,28 +217,34 @@ func TestManifestSchema1LayerInfo(t *testing.T) {
} {
assert.Equal(t, []types.BlobInfo{
{
Digest: "sha256:9cadd93b16ff2a0c51ac967ea2abfadfac50cfa3af8b5bf983d89b8f8647f3e4",
Size: -1,
Digest: "sha256:9cadd93b16ff2a0c51ac967ea2abfadfac50cfa3af8b5bf983d89b8f8647f3e4",
Size: -1,
MediaType: manifest.DockerV2Schema2LayerMediaType,
},
{
Digest: "sha256:4aa565ad8b7a87248163ce7dba1dd3894821aac97e846b932ff6b8ef9a8a508a",
Size: -1,
Digest: "sha256:4aa565ad8b7a87248163ce7dba1dd3894821aac97e846b932ff6b8ef9a8a508a",
Size: -1,
MediaType: manifest.DockerV2Schema2LayerMediaType,
},
{
Digest: "sha256:f576d102e09b9eef0e305aaef705d2d43a11bebc3fd5810a761624bd5e11997e",
Size: -1,
Digest: "sha256:f576d102e09b9eef0e305aaef705d2d43a11bebc3fd5810a761624bd5e11997e",
Size: -1,
MediaType: manifest.DockerV2Schema2LayerMediaType,
},
{
Digest: "sha256:9e92df2aea7dc0baf5f1f8d509678d6a6306de27ad06513f8e218371938c07a6",
Size: -1,
Digest: "sha256:9e92df2aea7dc0baf5f1f8d509678d6a6306de27ad06513f8e218371938c07a6",
Size: -1,
MediaType: manifest.DockerV2Schema2LayerMediaType,
},
{
Digest: "sha256:62e48e39dc5b30b75a97f05bccc66efbae6058b860ee20a5c9a184b9d5e25788",
Size: -1,
Digest: "sha256:62e48e39dc5b30b75a97f05bccc66efbae6058b860ee20a5c9a184b9d5e25788",
Size: -1,
MediaType: manifest.DockerV2Schema2LayerMediaType,
},
{
Digest: "sha256:e623934bca8d1a74f51014256445937714481e49343a31bda2bc5f534748184d",
Size: -1,
Digest: "sha256:e623934bca8d1a74f51014256445937714481e49343a31bda2bc5f534748184d",
Size: -1,
MediaType: manifest.DockerV2Schema2LayerMediaType,
},
}, m.LayerInfos())
}
Expand Down
30 changes: 15 additions & 15 deletions image/docker_schema2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,21 +622,21 @@ func TestConvertToManifestSchema1(t *testing.T) {
s1Manifest, err := manifestSchema1FromManifest(convertedJSON)
require.NoError(t, err)
assert.Equal(t, []types.BlobInfo{
{Digest: "sha256:6a5a5368e0c2d3e5909184fa28ddfd56072e7ff3ee9a945876f7eee5896ef5ba", Size: -1},
{Digest: GzippedEmptyLayerDigest, Size: -1},
{Digest: GzippedEmptyLayerDigest, Size: -1},
{Digest: GzippedEmptyLayerDigest, Size: -1},
{Digest: "sha256:1bbf5d58d24c47512e234a5623474acf65ae00d4d1414272a893204f44cc680d", Size: -1},
{Digest: GzippedEmptyLayerDigest, Size: -1},
{Digest: "sha256:8f5dc8a4b12c307ac84de90cdd9a7f3915d1be04c9388868ca118831099c67a8", Size: -1},
{Digest: GzippedEmptyLayerDigest, Size: -1},
{Digest: GzippedEmptyLayerDigest, Size: -1},
{Digest: GzippedEmptyLayerDigest, Size: -1},
{Digest: GzippedEmptyLayerDigest, Size: -1},
{Digest: "sha256:bbd6b22eb11afce63cc76f6bc41042d99f10d6024c96b655dafba930b8d25908", Size: -1},
{Digest: "sha256:960e52ecf8200cbd84e70eb2ad8678f4367e50d14357021872c10fa3fc5935fb", Size: -1},
{Digest: GzippedEmptyLayerDigest, Size: -1},
{Digest: GzippedEmptyLayerDigest, Size: -1},
{Digest: "sha256:6a5a5368e0c2d3e5909184fa28ddfd56072e7ff3ee9a945876f7eee5896ef5ba", Size: -1, MediaType: manifest.DockerV2Schema2LayerMediaType},
{Digest: GzippedEmptyLayerDigest, Size: -1, MediaType: manifest.DockerV2Schema2LayerMediaType},
{Digest: GzippedEmptyLayerDigest, Size: -1, MediaType: manifest.DockerV2Schema2LayerMediaType},
{Digest: GzippedEmptyLayerDigest, Size: -1, MediaType: manifest.DockerV2Schema2LayerMediaType},
{Digest: "sha256:1bbf5d58d24c47512e234a5623474acf65ae00d4d1414272a893204f44cc680d", Size: -1, MediaType: manifest.DockerV2Schema2LayerMediaType},
{Digest: GzippedEmptyLayerDigest, Size: -1, MediaType: manifest.DockerV2Schema2LayerMediaType},
{Digest: "sha256:8f5dc8a4b12c307ac84de90cdd9a7f3915d1be04c9388868ca118831099c67a8", Size: -1, MediaType: manifest.DockerV2Schema2LayerMediaType},
{Digest: GzippedEmptyLayerDigest, Size: -1, MediaType: manifest.DockerV2Schema2LayerMediaType},
{Digest: GzippedEmptyLayerDigest, Size: -1, MediaType: manifest.DockerV2Schema2LayerMediaType},
{Digest: GzippedEmptyLayerDigest, Size: -1, MediaType: manifest.DockerV2Schema2LayerMediaType},
{Digest: GzippedEmptyLayerDigest, Size: -1, MediaType: manifest.DockerV2Schema2LayerMediaType},
{Digest: "sha256:bbd6b22eb11afce63cc76f6bc41042d99f10d6024c96b655dafba930b8d25908", Size: -1, MediaType: manifest.DockerV2Schema2LayerMediaType},
{Digest: "sha256:960e52ecf8200cbd84e70eb2ad8678f4367e50d14357021872c10fa3fc5935fb", Size: -1, MediaType: manifest.DockerV2Schema2LayerMediaType},
{Digest: GzippedEmptyLayerDigest, Size: -1, MediaType: manifest.DockerV2Schema2LayerMediaType},
{Digest: GzippedEmptyLayerDigest, Size: -1, MediaType: manifest.DockerV2Schema2LayerMediaType},
}, s1Manifest.LayerInfos())

// FIXME? Test also the various failure cases, if only to see that we don't crash?
Expand Down
30 changes: 15 additions & 15 deletions image/oci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,21 +436,21 @@ func TestManifestOCI1ConvertToManifestSchema1(t *testing.T) {
s1Manifest, err := manifestSchema1FromManifest(convertedJSON)
require.NoError(t, err)
assert.Equal(t, []types.BlobInfo{
{Digest: "sha256:6a5a5368e0c2d3e5909184fa28ddfd56072e7ff3ee9a945876f7eee5896ef5ba", Size: -1},
{Digest: GzippedEmptyLayerDigest, Size: -1},
{Digest: GzippedEmptyLayerDigest, Size: -1},
{Digest: GzippedEmptyLayerDigest, Size: -1},
{Digest: "sha256:1bbf5d58d24c47512e234a5623474acf65ae00d4d1414272a893204f44cc680d", Size: -1},
{Digest: GzippedEmptyLayerDigest, Size: -1},
{Digest: "sha256:8f5dc8a4b12c307ac84de90cdd9a7f3915d1be04c9388868ca118831099c67a8", Size: -1},
{Digest: GzippedEmptyLayerDigest, Size: -1},
{Digest: GzippedEmptyLayerDigest, Size: -1},
{Digest: GzippedEmptyLayerDigest, Size: -1},
{Digest: GzippedEmptyLayerDigest, Size: -1},
{Digest: "sha256:bbd6b22eb11afce63cc76f6bc41042d99f10d6024c96b655dafba930b8d25908", Size: -1},
{Digest: "sha256:960e52ecf8200cbd84e70eb2ad8678f4367e50d14357021872c10fa3fc5935fb", Size: -1},
{Digest: GzippedEmptyLayerDigest, Size: -1},
{Digest: GzippedEmptyLayerDigest, Size: -1},
{Digest: "sha256:6a5a5368e0c2d3e5909184fa28ddfd56072e7ff3ee9a945876f7eee5896ef5ba", Size: -1, MediaType: manifest.DockerV2Schema2LayerMediaType},
{Digest: GzippedEmptyLayerDigest, Size: -1, MediaType: manifest.DockerV2Schema2LayerMediaType},
{Digest: GzippedEmptyLayerDigest, Size: -1, MediaType: manifest.DockerV2Schema2LayerMediaType},
{Digest: GzippedEmptyLayerDigest, Size: -1, MediaType: manifest.DockerV2Schema2LayerMediaType},
{Digest: "sha256:1bbf5d58d24c47512e234a5623474acf65ae00d4d1414272a893204f44cc680d", Size: -1, MediaType: manifest.DockerV2Schema2LayerMediaType},
{Digest: GzippedEmptyLayerDigest, Size: -1, MediaType: manifest.DockerV2Schema2LayerMediaType},
{Digest: "sha256:8f5dc8a4b12c307ac84de90cdd9a7f3915d1be04c9388868ca118831099c67a8", Size: -1, MediaType: manifest.DockerV2Schema2LayerMediaType},
{Digest: GzippedEmptyLayerDigest, Size: -1, MediaType: manifest.DockerV2Schema2LayerMediaType},
{Digest: GzippedEmptyLayerDigest, Size: -1, MediaType: manifest.DockerV2Schema2LayerMediaType},
{Digest: GzippedEmptyLayerDigest, Size: -1, MediaType: manifest.DockerV2Schema2LayerMediaType},
{Digest: GzippedEmptyLayerDigest, Size: -1, MediaType: manifest.DockerV2Schema2LayerMediaType},
{Digest: "sha256:bbd6b22eb11afce63cc76f6bc41042d99f10d6024c96b655dafba930b8d25908", Size: -1, MediaType: manifest.DockerV2Schema2LayerMediaType},
{Digest: "sha256:960e52ecf8200cbd84e70eb2ad8678f4367e50d14357021872c10fa3fc5935fb", Size: -1, MediaType: manifest.DockerV2Schema2LayerMediaType},
{Digest: GzippedEmptyLayerDigest, Size: -1, MediaType: manifest.DockerV2Schema2LayerMediaType},
{Digest: GzippedEmptyLayerDigest, Size: -1, MediaType: manifest.DockerV2Schema2LayerMediaType},
}, s1Manifest.LayerInfos())

// FIXME? Test also the various failure cases, if only to see that we don't crash?
Expand Down
2 changes: 1 addition & 1 deletion manifest/docker_schema1.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (m *Schema1) LayerInfos() []LayerInfo {
layers := make([]LayerInfo, len(m.FSLayers))
for i, layer := range m.FSLayers { // NOTE: This includes empty layers (where m.History.V1Compatibility->ThrowAway)
layers[(len(m.FSLayers)-1)-i] = LayerInfo{
BlobInfo: types.BlobInfo{Digest: layer.BlobSum, Size: -1},
BlobInfo: types.BlobInfo{Digest: layer.BlobSum, Size: -1, MediaType: DockerV2Schema2LayerMediaType},
EmptyLayer: m.ExtractedV1Compatibility[i].ThrowAway,
}
}
Expand Down
30 changes: 15 additions & 15 deletions manifest/docker_schema1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,20 @@ func TestSchema1LayerInfos(t *testing.T) {
// seem not to set the "throwaway" flag.
m := manifestSchema1FromFixture(t, "schema2-to-schema1-by-docker.json") // FIXME: Test also Schema1FromComponents
assert.Equal(t, []LayerInfo{
{BlobInfo: types.BlobInfo{Digest: "sha256:6a5a5368e0c2d3e5909184fa28ddfd56072e7ff3ee9a945876f7eee5896ef5bb", Size: -1}, EmptyLayer: false},
{BlobInfo: types.BlobInfo{Digest: "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4", Size: -1}, EmptyLayer: true},
{BlobInfo: types.BlobInfo{Digest: "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4", Size: -1}, EmptyLayer: true},
{BlobInfo: types.BlobInfo{Digest: "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4", Size: -1}, EmptyLayer: true},
{BlobInfo: types.BlobInfo{Digest: "sha256:1bbf5d58d24c47512e234a5623474acf65ae00d4d1414272a893204f44cc680c", Size: -1}, EmptyLayer: false},
{BlobInfo: types.BlobInfo{Digest: "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4", Size: -1}, EmptyLayer: true},
{BlobInfo: types.BlobInfo{Digest: "sha256:8f5dc8a4b12c307ac84de90cdd9a7f3915d1be04c9388868ca118831099c67a9", Size: -1}, EmptyLayer: false},
{BlobInfo: types.BlobInfo{Digest: "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4", Size: -1}, EmptyLayer: true},
{BlobInfo: types.BlobInfo{Digest: "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4", Size: -1}, EmptyLayer: true},
{BlobInfo: types.BlobInfo{Digest: "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4", Size: -1}, EmptyLayer: true},
{BlobInfo: types.BlobInfo{Digest: "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4", Size: -1}, EmptyLayer: true},
{BlobInfo: types.BlobInfo{Digest: "sha256:bbd6b22eb11afce63cc76f6bc41042d99f10d6024c96b655dafba930b8d25909", Size: -1}, EmptyLayer: false},
{BlobInfo: types.BlobInfo{Digest: "sha256:960e52ecf8200cbd84e70eb2ad8678f4367e50d14357021872c10fa3fc5935fa", Size: -1}, EmptyLayer: false},
{BlobInfo: types.BlobInfo{Digest: "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4", Size: -1}, EmptyLayer: true},
{BlobInfo: types.BlobInfo{Digest: "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4", Size: -1}, EmptyLayer: true},
{BlobInfo: types.BlobInfo{Digest: "sha256:6a5a5368e0c2d3e5909184fa28ddfd56072e7ff3ee9a945876f7eee5896ef5bb", Size: -1, MediaType: DockerV2Schema2LayerMediaType}, EmptyLayer: false},
{BlobInfo: types.BlobInfo{Digest: "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4", Size: -1, MediaType: DockerV2Schema2LayerMediaType}, EmptyLayer: true},
{BlobInfo: types.BlobInfo{Digest: "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4", Size: -1, MediaType: DockerV2Schema2LayerMediaType}, EmptyLayer: true},
{BlobInfo: types.BlobInfo{Digest: "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4", Size: -1, MediaType: DockerV2Schema2LayerMediaType}, EmptyLayer: true},
{BlobInfo: types.BlobInfo{Digest: "sha256:1bbf5d58d24c47512e234a5623474acf65ae00d4d1414272a893204f44cc680c", Size: -1, MediaType: DockerV2Schema2LayerMediaType}, EmptyLayer: false},
{BlobInfo: types.BlobInfo{Digest: "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4", Size: -1, MediaType: DockerV2Schema2LayerMediaType}, EmptyLayer: true},
{BlobInfo: types.BlobInfo{Digest: "sha256:8f5dc8a4b12c307ac84de90cdd9a7f3915d1be04c9388868ca118831099c67a9", Size: -1, MediaType: DockerV2Schema2LayerMediaType}, EmptyLayer: false},
{BlobInfo: types.BlobInfo{Digest: "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4", Size: -1, MediaType: DockerV2Schema2LayerMediaType}, EmptyLayer: true},
{BlobInfo: types.BlobInfo{Digest: "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4", Size: -1, MediaType: DockerV2Schema2LayerMediaType}, EmptyLayer: true},
{BlobInfo: types.BlobInfo{Digest: "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4", Size: -1, MediaType: DockerV2Schema2LayerMediaType}, EmptyLayer: true},
{BlobInfo: types.BlobInfo{Digest: "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4", Size: -1, MediaType: DockerV2Schema2LayerMediaType}, EmptyLayer: true},
{BlobInfo: types.BlobInfo{Digest: "sha256:bbd6b22eb11afce63cc76f6bc41042d99f10d6024c96b655dafba930b8d25909", Size: -1, MediaType: DockerV2Schema2LayerMediaType}, EmptyLayer: false},
{BlobInfo: types.BlobInfo{Digest: "sha256:960e52ecf8200cbd84e70eb2ad8678f4367e50d14357021872c10fa3fc5935fa", Size: -1, MediaType: DockerV2Schema2LayerMediaType}, EmptyLayer: false},
{BlobInfo: types.BlobInfo{Digest: "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4", Size: -1, MediaType: DockerV2Schema2LayerMediaType}, EmptyLayer: true},
{BlobInfo: types.BlobInfo{Digest: "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4", Size: -1, MediaType: DockerV2Schema2LayerMediaType}, EmptyLayer: true},
}, m.LayerInfos())
}

0 comments on commit fd2134a

Please sign in to comment.