diff --git a/manifest/manifestlist/manifestlist.go b/manifest/manifestlist/manifestlist.go index 7424f3ec..49e2b1af 100644 --- a/manifest/manifestlist/manifestlist.go +++ b/manifest/manifestlist/manifestlist.go @@ -17,6 +17,7 @@ const MediaTypeManifestList = "application/vnd.docker.distribution.manifest.list // packages version of the manifest. var SchemaVersion = manifest.Versioned{ SchemaVersion: 2, + MediaType: MediaTypeManifestList, } func init() { @@ -68,10 +69,6 @@ type ManifestDescriptor struct { type ManifestList struct { manifest.Versioned - // MediaType is the media type of this document. It should always - // be set to MediaTypeManifestList. - MediaType string `json:"mediaType"` - // Config references the image configuration as a blob. Manifests []ManifestDescriptor `json:"manifests"` } @@ -102,7 +99,6 @@ type DeserializedManifestList struct { func FromDescriptors(descriptors []ManifestDescriptor) (*DeserializedManifestList, error) { m := ManifestList{ Versioned: SchemaVersion, - MediaType: MediaTypeManifestList, } m.Manifests = make([]ManifestDescriptor, len(descriptors), len(descriptors)) diff --git a/manifest/schema2/builder.go b/manifest/schema2/builder.go index 1586bb99..70b006a8 100644 --- a/manifest/schema2/builder.go +++ b/manifest/schema2/builder.go @@ -4,7 +4,6 @@ import ( "github.com/docker/distribution" "github.com/docker/distribution/context" "github.com/docker/distribution/digest" - "github.com/docker/distribution/manifest" ) // builder is a type for constructing manifests. @@ -36,10 +35,7 @@ func NewManifestBuilder(bs distribution.BlobService, configJSON []byte) distribu // Build produces a final manifest from the given references. func (mb *builder) Build(ctx context.Context) (distribution.Manifest, error) { m := Manifest{ - Versioned: manifest.Versioned{ - SchemaVersion: 2, - }, - MediaType: MediaTypeManifest, + Versioned: SchemaVersion, Layers: make([]distribution.Descriptor, len(mb.layers)), } copy(m.Layers, mb.layers) diff --git a/manifest/schema2/manifest.go b/manifest/schema2/manifest.go index ea422da1..8d378e99 100644 --- a/manifest/schema2/manifest.go +++ b/manifest/schema2/manifest.go @@ -27,6 +27,7 @@ var ( // packages version of the manifest. SchemaVersion = manifest.Versioned{ SchemaVersion: 2, + MediaType: MediaTypeManifest, } ) @@ -50,7 +51,6 @@ func init() { // Manifest defines a schema2 manifest. type Manifest struct { manifest.Versioned - MediaType string `json:"mediaType"` // Config references the image configuration as a blob. Config distribution.Descriptor `json:"config"` diff --git a/manifest/schema2/manifest_test.go b/manifest/schema2/manifest_test.go index 59b8af69..459d614c 100644 --- a/manifest/schema2/manifest_test.go +++ b/manifest/schema2/manifest_test.go @@ -29,7 +29,6 @@ var expectedManifestSerialization = []byte(`{ func TestManifest(t *testing.T) { manifest := Manifest{ Versioned: SchemaVersion, - MediaType: MediaTypeManifest, Config: distribution.Descriptor{ Digest: "sha256:1a9ec845ee94c202b2d5da74a24f0ed2058318bfa9879fa541efaecba272e86b", Size: 985, diff --git a/manifest/versioned.go b/manifest/versioned.go index bef38292..c57398bd 100644 --- a/manifest/versioned.go +++ b/manifest/versioned.go @@ -1,9 +1,12 @@ package manifest -// Versioned provides a struct with just the manifest schemaVersion. Incoming +// Versioned provides a struct with the manifest schemaVersion and . Incoming // content with unknown schema version can be decoded against this struct to // check the version. type Versioned struct { // SchemaVersion is the image manifest schema that this image follows SchemaVersion int `json:"schemaVersion"` + + // MediaType is the media type of this schema. + MediaType string `json:"mediaType,omitempty"` } diff --git a/registry/handlers/api_test.go b/registry/handlers/api_test.go index 50a8cb47..8195f47b 100644 --- a/registry/handlers/api_test.go +++ b/registry/handlers/api_test.go @@ -1096,8 +1096,8 @@ func testManifestAPISchema2(t *testing.T, env *testEnv, imageName string) manife manifest := &schema2.Manifest{ Versioned: manifest.Versioned{ SchemaVersion: 2, + MediaType: schema2.MediaTypeManifest, }, - MediaType: schema2.MediaTypeManifest, Config: distribution.Descriptor{ Digest: "sha256:1a9ec845ee94c202b2d5da74a24f0ed2058318bfa9879fa541efaecba272e86b", Size: 3253, @@ -1410,8 +1410,8 @@ func testManifestAPIManifestList(t *testing.T, env *testEnv, args manifestArgs) manifestList := &manifestlist.ManifestList{ Versioned: manifest.Versioned{ SchemaVersion: 2, + MediaType: manifestlist.MediaTypeManifestList, }, - MediaType: manifestlist.MediaTypeManifestList, Manifests: []manifestlist.ManifestDescriptor{ { Descriptor: distribution.Descriptor{ diff --git a/registry/storage/manifeststore.go b/registry/storage/manifeststore.go index cd01670b..31daa83c 100644 --- a/registry/storage/manifeststore.go +++ b/registry/storage/manifeststore.go @@ -95,19 +95,13 @@ func (ms *manifestStore) Get(ctx context.Context, dgst digest.Digest, options .. return ms.schema1Handler.Unmarshal(ctx, dgst, content) case 2: // This can be an image manifest or a manifest list - var mediaType struct { - MediaType string `json:"mediaType"` - } - if err = json.Unmarshal(content, &mediaType); err != nil { - return nil, err - } - switch mediaType.MediaType { + switch versioned.MediaType { case schema2.MediaTypeManifest: return ms.schema2Handler.Unmarshal(ctx, dgst, content) case manifestlist.MediaTypeManifestList: return ms.manifestListHandler.Unmarshal(ctx, dgst, content) default: - return nil, distribution.ErrManifestVerification{fmt.Errorf("unrecognized manifest content type %s", mediaType.MediaType)} + return nil, distribution.ErrManifestVerification{fmt.Errorf("unrecognized manifest content type %s", versioned.MediaType)} } }