Move MediaType into manifest.Versioned

This makes content type sniffing cleaner. The document just needs to be
decoded into a manifest.Versioned structure. It's no longer a two-step
process.

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
This commit is contained in:
Aaron Lehmann 2016-01-06 14:15:14 -08:00
parent 697af09566
commit 6d17423a6d
7 changed files with 11 additions and 23 deletions

View file

@ -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))

View file

@ -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)

View file

@ -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"`

View file

@ -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,

View file

@ -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"`
}