deprecate Versioned in favor of oci.Versioned (#3887)

This commit is contained in:
Milos Gajdos 2024-07-18 19:44:14 +01:00 committed by GitHub
commit 33b657b5ae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 133 additions and 106 deletions

View file

@ -18,13 +18,13 @@ import (
"github.com/distribution/distribution/v3" "github.com/distribution/distribution/v3"
"github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/distribution/v3/internal/dcontext"
"github.com/distribution/distribution/v3/manifest"
"github.com/distribution/distribution/v3/manifest/ocischema" "github.com/distribution/distribution/v3/manifest/ocischema"
"github.com/distribution/distribution/v3/registry/api/errcode" "github.com/distribution/distribution/v3/registry/api/errcode"
"github.com/distribution/distribution/v3/testutil" "github.com/distribution/distribution/v3/testutil"
"github.com/distribution/reference" "github.com/distribution/reference"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/opencontainers/go-digest" "github.com/opencontainers/go-digest"
"github.com/opencontainers/image-spec/specs-go"
v1 "github.com/opencontainers/image-spec/specs-go/v1" v1 "github.com/opencontainers/image-spec/specs-go/v1"
) )
@ -928,10 +928,8 @@ func newRandomOCIManifest(t *testing.T, blobCount int) (*ocischema.Manifest, dig
} }
m := ocischema.Manifest{ m := ocischema.Manifest{
Versioned: manifest.Versioned{ Versioned: specs.Versioned{SchemaVersion: 2},
SchemaVersion: 2, MediaType: v1.MediaTypeImageManifest,
MediaType: v1.MediaTypeImageManifest,
},
Config: distribution.Descriptor{ Config: distribution.Descriptor{
Digest: "sha256:1a9ec845ee94c202b2d5da74a24f0ed2058318bfa9879fa541efaecba272e86b", Digest: "sha256:1a9ec845ee94c202b2d5da74a24f0ed2058318bfa9879fa541efaecba272e86b",
Size: 123, Size: 123,

View file

@ -8,6 +8,7 @@ import (
"github.com/distribution/distribution/v3" "github.com/distribution/distribution/v3"
"github.com/distribution/distribution/v3/manifest" "github.com/distribution/distribution/v3/manifest"
"github.com/opencontainers/go-digest" "github.com/opencontainers/go-digest"
"github.com/opencontainers/image-spec/specs-go"
v1 "github.com/opencontainers/image-spec/specs-go/v1" v1 "github.com/opencontainers/image-spec/specs-go/v1"
) )
@ -18,6 +19,11 @@ const (
// SchemaVersion provides a pre-initialized version structure for this // SchemaVersion provides a pre-initialized version structure for this
// packages version of the manifest. // packages version of the manifest.
//
// Deprecated: use [specs.Versioned] and set MediaType on the manifest
// to [MediaTypeManifestList].
//
//nolint:staticcheck // ignore SA1019: manifest.Versioned is deprecated:
var SchemaVersion = manifest.Versioned{ var SchemaVersion = manifest.Versioned{
SchemaVersion: 2, SchemaVersion: 2,
MediaType: MediaTypeManifestList, MediaType: MediaTypeManifestList,
@ -84,7 +90,10 @@ type ManifestDescriptor struct {
// ManifestList references manifests for various platforms. // ManifestList references manifests for various platforms.
type ManifestList struct { type ManifestList struct {
manifest.Versioned specs.Versioned
// MediaType is the media type of this schema.
MediaType string `json:"mediaType,omitempty"`
// Manifests references a list of manifests // Manifests references a list of manifests
Manifests []ManifestDescriptor `json:"manifests"` Manifests []ManifestDescriptor `json:"manifests"`
@ -127,10 +136,8 @@ func FromDescriptors(descriptors []ManifestDescriptor) (*DeserializedManifestLis
// fromDescriptorsWithMediaType is for testing purposes, it's useful to be able to specify the media type explicitly // fromDescriptorsWithMediaType is for testing purposes, it's useful to be able to specify the media type explicitly
func fromDescriptorsWithMediaType(descriptors []ManifestDescriptor, mediaType string) (*DeserializedManifestList, error) { func fromDescriptorsWithMediaType(descriptors []ManifestDescriptor, mediaType string) (*DeserializedManifestList, error) {
m := ManifestList{ m := ManifestList{
Versioned: manifest.Versioned{ Versioned: specs.Versioned{SchemaVersion: 2},
SchemaVersion: SchemaVersion.SchemaVersion, MediaType: mediaType,
MediaType: mediaType,
},
} }
m.Manifests = make([]ManifestDescriptor, len(descriptors)) m.Manifests = make([]ManifestDescriptor, len(descriptors))
@ -175,7 +182,14 @@ func (m *DeserializedManifestList) MarshalJSON() ([]byte, error) {
// Payload returns the raw content of the manifest list. The contents can be // Payload returns the raw content of the manifest list. The contents can be
// used to calculate the content identifier. // used to calculate the content identifier.
func (m DeserializedManifestList) Payload() (string, []byte, error) { func (m DeserializedManifestList) Payload() (string, []byte, error) {
return m.MediaType, m.canonical, nil var mediaType string
if m.MediaType == "" {
mediaType = v1.MediaTypeImageIndex
} else {
mediaType = m.MediaType
}
return mediaType, m.canonical, nil
} }
// validateManifestList returns an error if the byte slice is invalid JSON or if it // validateManifestList returns an error if the byte slice is invalid JSON or if it

View file

@ -5,8 +5,8 @@ import (
"errors" "errors"
"github.com/distribution/distribution/v3" "github.com/distribution/distribution/v3"
"github.com/distribution/distribution/v3/manifest"
"github.com/opencontainers/go-digest" "github.com/opencontainers/go-digest"
"github.com/opencontainers/image-spec/specs-go"
v1 "github.com/opencontainers/image-spec/specs-go/v1" v1 "github.com/opencontainers/image-spec/specs-go/v1"
) )
@ -58,10 +58,8 @@ func (mb *Builder) SetMediaType(mediaType string) error {
// Build produces a final manifest from the given references. // Build produces a final manifest from the given references.
func (mb *Builder) Build(ctx context.Context) (distribution.Manifest, error) { func (mb *Builder) Build(ctx context.Context) (distribution.Manifest, error) {
m := Manifest{ m := Manifest{
Versioned: manifest.Versioned{ Versioned: specs.Versioned{SchemaVersion: 2},
SchemaVersion: 2, MediaType: mb.mediaType,
MediaType: mb.mediaType,
},
Layers: make([]distribution.Descriptor, len(mb.layers)), Layers: make([]distribution.Descriptor, len(mb.layers)),
Annotations: mb.annotations, Annotations: mb.annotations,
} }

View file

@ -8,11 +8,17 @@ import (
"github.com/distribution/distribution/v3" "github.com/distribution/distribution/v3"
"github.com/distribution/distribution/v3/manifest" "github.com/distribution/distribution/v3/manifest"
"github.com/opencontainers/go-digest" "github.com/opencontainers/go-digest"
"github.com/opencontainers/image-spec/specs-go"
v1 "github.com/opencontainers/image-spec/specs-go/v1" v1 "github.com/opencontainers/image-spec/specs-go/v1"
) )
// IndexSchemaVersion provides a pre-initialized version structure for OCI Image // IndexSchemaVersion provides a pre-initialized version structure for OCI Image
// Indices. // Indices.
//
// Deprecated: use [specs.Versioned] and set MediaType on the manifest
// to [v1.MediaTypeImageIndex].
//
//nolint:staticcheck // ignore SA1019: manifest.Versioned is deprecated:
var IndexSchemaVersion = manifest.Versioned{ var IndexSchemaVersion = manifest.Versioned{
SchemaVersion: 2, SchemaVersion: 2,
MediaType: v1.MediaTypeImageIndex, MediaType: v1.MediaTypeImageIndex,
@ -48,7 +54,10 @@ func unmarshalImageIndex(b []byte) (distribution.Manifest, distribution.Descript
// ImageIndex references manifests for various platforms. // ImageIndex references manifests for various platforms.
type ImageIndex struct { type ImageIndex struct {
manifest.Versioned specs.Versioned
// MediaType is the media type of this schema.
MediaType string `json:"mediaType,omitempty"`
// Manifests references a list of manifests // Manifests references a list of manifests
Manifests []distribution.Descriptor `json:"manifests"` Manifests []distribution.Descriptor `json:"manifests"`
@ -84,10 +93,8 @@ func FromDescriptors(descriptors []distribution.Descriptor, annotations map[stri
// fromDescriptorsWithMediaType is for testing purposes, it's useful to be able to specify the media type explicitly // fromDescriptorsWithMediaType is for testing purposes, it's useful to be able to specify the media type explicitly
func fromDescriptorsWithMediaType(descriptors []distribution.Descriptor, annotations map[string]string, mediaType string) (_ *DeserializedImageIndex, err error) { func fromDescriptorsWithMediaType(descriptors []distribution.Descriptor, annotations map[string]string, mediaType string) (_ *DeserializedImageIndex, err error) {
m := ImageIndex{ m := ImageIndex{
Versioned: manifest.Versioned{ Versioned: specs.Versioned{SchemaVersion: 2},
SchemaVersion: IndexSchemaVersion.SchemaVersion, MediaType: mediaType,
MediaType: mediaType,
},
Annotations: annotations, Annotations: annotations,
} }

View file

@ -8,11 +8,17 @@ import (
"github.com/distribution/distribution/v3" "github.com/distribution/distribution/v3"
"github.com/distribution/distribution/v3/manifest" "github.com/distribution/distribution/v3/manifest"
"github.com/opencontainers/go-digest" "github.com/opencontainers/go-digest"
"github.com/opencontainers/image-spec/specs-go"
v1 "github.com/opencontainers/image-spec/specs-go/v1" v1 "github.com/opencontainers/image-spec/specs-go/v1"
) )
// SchemaVersion provides a pre-initialized version structure for OCI Image // SchemaVersion provides a pre-initialized version structure for OCI Image
// Manifests // Manifests.
//
// Deprecated: use [specs.Versioned] and set MediaType on the manifest
// to [v1.MediaTypeImageManifest].
//
//nolint:staticcheck // ignore SA1019: manifest.Versioned is deprecated:
var SchemaVersion = manifest.Versioned{ var SchemaVersion = manifest.Versioned{
SchemaVersion: 2, SchemaVersion: 2,
MediaType: v1.MediaTypeImageManifest, MediaType: v1.MediaTypeImageManifest,
@ -44,7 +50,10 @@ func unmarshalOCISchema(b []byte) (distribution.Manifest, distribution.Descripto
// Manifest defines a ocischema manifest. // Manifest defines a ocischema manifest.
type Manifest struct { type Manifest struct {
manifest.Versioned specs.Versioned
// MediaType is the media type of this schema.
MediaType string `json:"mediaType,omitempty"`
// Config references the image configuration as a blob. // Config references the image configuration as a blob.
Config distribution.Descriptor `json:"config"` Config distribution.Descriptor `json:"config"`
@ -124,7 +133,7 @@ func (m *DeserializedManifest) MarshalJSON() ([]byte, error) {
// Payload returns the raw content of the manifest. The contents can be used to // Payload returns the raw content of the manifest. The contents can be used to
// calculate the content identifier. // calculate the content identifier.
func (m DeserializedManifest) Payload() (string, []byte, error) { func (m *DeserializedManifest) Payload() (string, []byte, error) {
return v1.MediaTypeImageManifest, m.canonical, nil return v1.MediaTypeImageManifest, m.canonical, nil
} }

View file

@ -7,8 +7,8 @@ import (
"testing" "testing"
"github.com/distribution/distribution/v3" "github.com/distribution/distribution/v3"
"github.com/distribution/distribution/v3/manifest"
"github.com/distribution/distribution/v3/manifest/manifestlist" "github.com/distribution/distribution/v3/manifest/manifestlist"
"github.com/opencontainers/image-spec/specs-go"
"github.com/opencontainers/go-digest" "github.com/opencontainers/go-digest"
v1 "github.com/opencontainers/image-spec/specs-go/v1" v1 "github.com/opencontainers/image-spec/specs-go/v1"
@ -42,10 +42,8 @@ const expectedManifestSerialization = `{
func makeTestManifest(mediaType string) Manifest { func makeTestManifest(mediaType string) Manifest {
return Manifest{ return Manifest{
Versioned: manifest.Versioned{ Versioned: specs.Versioned{SchemaVersion: 2},
SchemaVersion: 2, MediaType: mediaType,
MediaType: mediaType,
},
Config: distribution.Descriptor{ Config: distribution.Descriptor{
MediaType: v1.MediaTypeImageConfig, MediaType: v1.MediaTypeImageConfig,
Digest: "sha256:1a9ec845ee94c202b2d5da74a24f0ed2058318bfa9879fa541efaecba272e86b", Digest: "sha256:1a9ec845ee94c202b2d5da74a24f0ed2058318bfa9879fa541efaecba272e86b",

View file

@ -4,6 +4,7 @@ import (
"context" "context"
"github.com/distribution/distribution/v3" "github.com/distribution/distribution/v3"
"github.com/opencontainers/image-spec/specs-go"
) )
// Builder is a type for constructing manifests. // Builder is a type for constructing manifests.
@ -35,7 +36,8 @@ func NewManifestBuilder(configDescriptor distribution.Descriptor, configJSON []b
// Build produces a final manifest from the given references. // Build produces a final manifest from the given references.
func (mb *Builder) Build(ctx context.Context) (distribution.Manifest, error) { func (mb *Builder) Build(ctx context.Context) (distribution.Manifest, error) {
m := Manifest{ m := Manifest{
Versioned: SchemaVersion, Versioned: specs.Versioned{SchemaVersion: defaultSchemaVersion},
MediaType: defaultMediaType,
Layers: make([]distribution.Descriptor, len(mb.dependencies)), Layers: make([]distribution.Descriptor, len(mb.dependencies)),
} }
copy(m.Layers, mb.dependencies) copy(m.Layers, mb.dependencies)

View file

@ -8,6 +8,7 @@ import (
"github.com/distribution/distribution/v3" "github.com/distribution/distribution/v3"
"github.com/distribution/distribution/v3/manifest" "github.com/distribution/distribution/v3/manifest"
"github.com/opencontainers/go-digest" "github.com/opencontainers/go-digest"
"github.com/opencontainers/image-spec/specs-go"
) )
const ( const (
@ -33,15 +34,25 @@ const (
MediaTypeUncompressedLayer = "application/vnd.docker.image.rootfs.diff.tar" MediaTypeUncompressedLayer = "application/vnd.docker.image.rootfs.diff.tar"
) )
const (
defaultSchemaVersion = 2
defaultMediaType = MediaTypeManifest
)
// SchemaVersion provides a pre-initialized version structure for this // SchemaVersion provides a pre-initialized version structure for this
// packages version of the manifest. // packages version of the manifest.
//
// Deprecated: use [specs.Versioned] and set MediaType on the manifest
// to [MediaTypeManifest].
//
//nolint:staticcheck // ignore SA1019: manifest.Versioned is deprecated:
var SchemaVersion = manifest.Versioned{ var SchemaVersion = manifest.Versioned{
SchemaVersion: 2, SchemaVersion: defaultSchemaVersion,
MediaType: MediaTypeManifest, MediaType: defaultMediaType,
} }
func init() { func init() {
if err := distribution.RegisterManifestSchema(MediaTypeManifest, unmarshalSchema2); err != nil { if err := distribution.RegisterManifestSchema(defaultMediaType, unmarshalSchema2); err != nil {
panic(fmt.Sprintf("Unable to register manifest: %s", err)) panic(fmt.Sprintf("Unable to register manifest: %s", err))
} }
} }
@ -55,13 +66,16 @@ func unmarshalSchema2(b []byte) (distribution.Manifest, distribution.Descriptor,
return m, distribution.Descriptor{ return m, distribution.Descriptor{
Digest: digest.FromBytes(b), Digest: digest.FromBytes(b),
Size: int64(len(b)), Size: int64(len(b)),
MediaType: MediaTypeManifest, MediaType: defaultMediaType,
}, nil }, nil
} }
// Manifest defines a schema2 manifest. // Manifest defines a schema2 manifest.
type Manifest struct { type Manifest struct {
manifest.Versioned specs.Versioned
// MediaType is the media type of this schema.
MediaType string `json:"mediaType,omitempty"`
// Config references the image configuration as a blob. // Config references the image configuration as a blob.
Config distribution.Descriptor `json:"config"` Config distribution.Descriptor `json:"config"`
@ -116,9 +130,8 @@ func (m *DeserializedManifest) UnmarshalJSON(b []byte) error {
return err return err
} }
if mfst.MediaType != MediaTypeManifest { if mfst.MediaType != defaultMediaType {
return fmt.Errorf("mediaType in manifest should be '%s' not '%s'", return fmt.Errorf("mediaType in manifest should be '%s' not '%s'", defaultMediaType, mfst.MediaType)
MediaTypeManifest, mfst.MediaType)
} }
m.Manifest = mfst m.Manifest = mfst

View file

@ -7,7 +7,7 @@ import (
"testing" "testing"
"github.com/distribution/distribution/v3" "github.com/distribution/distribution/v3"
"github.com/distribution/distribution/v3/manifest" "github.com/opencontainers/image-spec/specs-go"
) )
const expectedManifestSerialization = `{ const expectedManifestSerialization = `{
@ -29,10 +29,8 @@ const expectedManifestSerialization = `{
func makeTestManifest(mediaType string) Manifest { func makeTestManifest(mediaType string) Manifest {
return Manifest{ return Manifest{
Versioned: manifest.Versioned{ Versioned: specs.Versioned{SchemaVersion: 2},
SchemaVersion: 2, MediaType: mediaType,
MediaType: mediaType,
},
Config: distribution.Descriptor{ Config: distribution.Descriptor{
MediaType: MediaTypeImageConfig, MediaType: MediaTypeImageConfig,
Digest: "sha256:1a9ec845ee94c202b2d5da74a24f0ed2058318bfa9879fa541efaecba272e86b", Digest: "sha256:1a9ec845ee94c202b2d5da74a24f0ed2058318bfa9879fa541efaecba272e86b",

View file

@ -3,6 +3,8 @@ package manifest
// Versioned provides a struct with the manifest schemaVersion and mediaType. // Versioned provides a struct with the manifest schemaVersion and mediaType.
// Incoming content with unknown schema version can be decoded against this // Incoming content with unknown schema version can be decoded against this
// struct to check the version. // struct to check the version.
//
// Deprecated: use [specs.Versioned] and set MediaType on the Manifest itself.
type Versioned struct { type Versioned struct {
// SchemaVersion is the image manifest schema that this image follows // SchemaVersion is the image manifest schema that this image follows
SchemaVersion int `json:"schemaVersion"` SchemaVersion int `json:"schemaVersion"`

View file

@ -4,13 +4,13 @@ import (
"testing" "testing"
"github.com/distribution/distribution/v3" "github.com/distribution/distribution/v3"
"github.com/distribution/distribution/v3/manifest"
"github.com/distribution/distribution/v3/manifest/schema2" "github.com/distribution/distribution/v3/manifest/schema2"
v2 "github.com/distribution/distribution/v3/registry/api/v2" v2 "github.com/distribution/distribution/v3/registry/api/v2"
"github.com/distribution/reference" "github.com/distribution/reference"
events "github.com/docker/go-events" events "github.com/docker/go-events"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/opencontainers/go-digest" "github.com/opencontainers/go-digest"
"github.com/opencontainers/image-spec/specs-go"
v1 "github.com/opencontainers/image-spec/specs-go/v1" v1 "github.com/opencontainers/image-spec/specs-go/v1"
) )
@ -29,7 +29,6 @@ var (
} }
request = RequestRecord{} request = RequestRecord{}
tag = "latest" tag = "latest"
ociMediaType = v1.MediaTypeImageManifest
artifactType = "application/vnd.example.sbom.v1" artifactType = "application/vnd.example.sbom.v1"
cfg = distribution.Descriptor{ cfg = distribution.Descriptor{
MediaType: artifactType, MediaType: artifactType,
@ -143,14 +142,13 @@ func TestEventBridgeRepoDeleted(t *testing.T) {
} }
func createTestEnv(t *testing.T, fn testSinkFn) Listener { func createTestEnv(t *testing.T, fn testSinkFn) Listener {
manifest := schema2.Manifest{ mfst := schema2.Manifest{
Versioned: manifest.Versioned{ Versioned: specs.Versioned{SchemaVersion: 2},
MediaType: ociMediaType, MediaType: v1.MediaTypeImageManifest,
}, Config: cfg,
Config: cfg,
} }
deserializedManifest, err := schema2.FromStruct(manifest) deserializedManifest, err := schema2.FromStruct(mfst)
if err != nil { if err != nil {
t.Fatalf("creating OCI manifest: %v", err) t.Fatalf("creating OCI manifest: %v", err)
} }

View file

@ -14,6 +14,7 @@ import (
"github.com/distribution/distribution/v3/testutil" "github.com/distribution/distribution/v3/testutil"
"github.com/distribution/reference" "github.com/distribution/reference"
"github.com/opencontainers/go-digest" "github.com/opencontainers/go-digest"
"github.com/opencontainers/image-spec/specs-go"
) )
func TestListener(t *testing.T) { func TestListener(t *testing.T) {
@ -143,7 +144,8 @@ func checkTestRepository(t *testing.T, repository distribution.Repository, remov
} }
m := schema2.Manifest{ m := schema2.Manifest{
Versioned: schema2.SchemaVersion, Versioned: specs.Versioned{SchemaVersion: 2},
MediaType: schema2.MediaTypeManifest,
Config: distribution.Descriptor{ Config: distribution.Descriptor{
MediaType: "foo/bar", MediaType: "foo/bar",
Digest: configDgst, Digest: configDgst,

View file

@ -21,7 +21,6 @@ import (
"github.com/distribution/distribution/v3" "github.com/distribution/distribution/v3"
"github.com/distribution/distribution/v3/configuration" "github.com/distribution/distribution/v3/configuration"
"github.com/distribution/distribution/v3/manifest"
"github.com/distribution/distribution/v3/manifest/manifestlist" "github.com/distribution/distribution/v3/manifest/manifestlist"
"github.com/distribution/distribution/v3/manifest/schema2" "github.com/distribution/distribution/v3/manifest/schema2"
"github.com/distribution/distribution/v3/registry/api/errcode" "github.com/distribution/distribution/v3/registry/api/errcode"
@ -33,6 +32,7 @@ import (
"github.com/distribution/reference" "github.com/distribution/reference"
"github.com/gorilla/handlers" "github.com/gorilla/handlers"
"github.com/opencontainers/go-digest" "github.com/opencontainers/go-digest"
"github.com/opencontainers/image-spec/specs-go"
) )
var headerConfig = http.Header{ var headerConfig = http.Header{
@ -1577,10 +1577,8 @@ func testManifestAPISchema2(t *testing.T, env *testEnv, imageName reference.Name
// -------------------------------- // --------------------------------
// Attempt to push manifest with missing config and missing layers // Attempt to push manifest with missing config and missing layers
manifest := &schema2.Manifest{ manifest := &schema2.Manifest{
Versioned: manifest.Versioned{ Versioned: specs.Versioned{SchemaVersion: 2},
SchemaVersion: 2, MediaType: schema2.MediaTypeManifest,
MediaType: schema2.MediaTypeManifest,
},
Config: distribution.Descriptor{ Config: distribution.Descriptor{
Digest: "sha256:1a9ec845ee94c202b2d5da74a24f0ed2058318bfa9879fa541efaecba272e86b", Digest: "sha256:1a9ec845ee94c202b2d5da74a24f0ed2058318bfa9879fa541efaecba272e86b",
Size: 3253, Size: 3253,
@ -1900,10 +1898,8 @@ func testManifestAPIManifestList(t *testing.T, env *testEnv, args manifestArgs)
// -------------------------------- // --------------------------------
// Attempt to push manifest list that refers to an unknown manifest // Attempt to push manifest list that refers to an unknown manifest
manifestList := &manifestlist.ManifestList{ manifestList := &manifestlist.ManifestList{
Versioned: manifest.Versioned{ Versioned: specs.Versioned{SchemaVersion: 2},
SchemaVersion: 2, MediaType: manifestlist.MediaTypeManifestList,
MediaType: manifestlist.MediaTypeManifestList,
},
Manifests: []manifestlist.ManifestDescriptor{ Manifests: []manifestlist.ManifestDescriptor{
{ {
Descriptor: distribution.Descriptor{ Descriptor: distribution.Descriptor{
@ -2639,10 +2635,8 @@ func createRepository(env *testEnv, t *testing.T, imageName string, tag string)
} }
manifest := &schema2.Manifest{ manifest := &schema2.Manifest{
Versioned: manifest.Versioned{ Versioned: specs.Versioned{SchemaVersion: 2},
SchemaVersion: 2, MediaType: schema2.MediaTypeManifest,
MediaType: schema2.MediaTypeManifest,
},
Config: distribution.Descriptor{ Config: distribution.Descriptor{
Digest: "sha256:1a9ec845ee94c202b2d5da74a24f0ed2058318bfa9879fa541efaecba272e86b", Digest: "sha256:1a9ec845ee94c202b2d5da74a24f0ed2058318bfa9879fa541efaecba272e86b",
Size: 3253, Size: 3253,
@ -2736,10 +2730,8 @@ func TestRegistryAsCacheMutationAPIs(t *testing.T) {
// Manifest upload // Manifest upload
manifest := &schema2.Manifest{ manifest := &schema2.Manifest{
Versioned: manifest.Versioned{ Versioned: specs.Versioned{SchemaVersion: 2},
SchemaVersion: 2, MediaType: schema2.MediaTypeManifest,
MediaType: schema2.MediaTypeManifest,
},
Config: distribution.Descriptor{ Config: distribution.Descriptor{
Digest: "sha256:1a9ec845ee94c202b2d5da74a24f0ed2058318bfa9879fa541efaecba272e86b", Digest: "sha256:1a9ec845ee94c202b2d5da74a24f0ed2058318bfa9879fa541efaecba272e86b",
Size: 3253, Size: 3253,

View file

@ -17,6 +17,7 @@ import (
"github.com/distribution/distribution/v3/testutil" "github.com/distribution/distribution/v3/testutil"
"github.com/distribution/reference" "github.com/distribution/reference"
"github.com/opencontainers/go-digest" "github.com/opencontainers/go-digest"
"github.com/opencontainers/image-spec/specs-go"
) )
type statsManifest struct { type statsManifest struct {
@ -153,7 +154,8 @@ func populateRepo(ctx context.Context, t *testing.T, repository distribution.Rep
} }
m := schema2.Manifest{ m := schema2.Manifest{
Versioned: schema2.SchemaVersion, Versioned: specs.Versioned{SchemaVersion: 2},
MediaType: schema2.MediaTypeManifest,
Config: distribution.Descriptor{ Config: distribution.Descriptor{
MediaType: "foo/bar", MediaType: "foo/bar",
Digest: configDigest, Digest: configDigest,

View file

@ -35,17 +35,17 @@ func (ms *manifestListHandler) Unmarshal(ctx context.Context, dgst digest.Digest
func (ms *manifestListHandler) Put(ctx context.Context, manifestList distribution.Manifest, skipDependencyVerification bool) (digest.Digest, error) { func (ms *manifestListHandler) Put(ctx context.Context, manifestList distribution.Manifest, skipDependencyVerification bool) (digest.Digest, error) {
dcontext.GetLogger(ms.ctx).Debug("(*manifestListHandler).Put") dcontext.GetLogger(ms.ctx).Debug("(*manifestListHandler).Put")
var schemaVersion, expectedSchemaVersion int var schemaVersion int
switch m := manifestList.(type) { switch m := manifestList.(type) {
case *manifestlist.DeserializedManifestList: case *manifestlist.DeserializedManifestList:
expectedSchemaVersion = manifestlist.SchemaVersion.SchemaVersion
schemaVersion = m.SchemaVersion schemaVersion = m.SchemaVersion
case *ocischema.DeserializedImageIndex: case *ocischema.DeserializedImageIndex:
expectedSchemaVersion = ocischema.IndexSchemaVersion.SchemaVersion
schemaVersion = m.SchemaVersion schemaVersion = m.SchemaVersion
default: default:
return "", fmt.Errorf("wrong type put to manifestListHandler: %T", manifestList) return "", fmt.Errorf("wrong type put to manifestListHandler: %T", manifestList)
} }
const expectedSchemaVersion = 2
if schemaVersion != expectedSchemaVersion { if schemaVersion != expectedSchemaVersion {
return "", fmt.Errorf("unrecognized manifest list schema version %d, expected %d", schemaVersion, expectedSchemaVersion) return "", fmt.Errorf("unrecognized manifest list schema version %d, expected %d", schemaVersion, expectedSchemaVersion)
} }

View file

@ -7,11 +7,11 @@ import (
"github.com/distribution/distribution/v3" "github.com/distribution/distribution/v3"
"github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/distribution/v3/internal/dcontext"
"github.com/distribution/distribution/v3/manifest"
"github.com/distribution/distribution/v3/manifest/manifestlist" "github.com/distribution/distribution/v3/manifest/manifestlist"
"github.com/distribution/distribution/v3/manifest/ocischema" "github.com/distribution/distribution/v3/manifest/ocischema"
"github.com/distribution/distribution/v3/manifest/schema2" "github.com/distribution/distribution/v3/manifest/schema2"
"github.com/opencontainers/go-digest" "github.com/opencontainers/go-digest"
"github.com/opencontainers/image-spec/specs-go"
v1 "github.com/opencontainers/image-spec/specs-go/v1" v1 "github.com/opencontainers/image-spec/specs-go/v1"
) )
@ -88,7 +88,13 @@ func (ms *manifestStore) Get(ctx context.Context, dgst digest.Digest, options ..
return nil, err return nil, err
} }
var versioned manifest.Versioned // versioned is a minimal representation of a manifest with version and mediatype.
var versioned struct {
specs.Versioned
// MediaType is the media type of this schema.
MediaType string `json:"mediaType,omitempty"`
}
if err = json.Unmarshal(content, &versioned); err != nil { if err = json.Unmarshal(content, &versioned); err != nil {
return nil, err return nil, err
} }

View file

@ -9,7 +9,6 @@ import (
"testing" "testing"
"github.com/distribution/distribution/v3" "github.com/distribution/distribution/v3"
"github.com/distribution/distribution/v3/manifest"
"github.com/distribution/distribution/v3/manifest/manifestlist" "github.com/distribution/distribution/v3/manifest/manifestlist"
"github.com/distribution/distribution/v3/manifest/ocischema" "github.com/distribution/distribution/v3/manifest/ocischema"
"github.com/distribution/distribution/v3/manifest/schema2" "github.com/distribution/distribution/v3/manifest/schema2"
@ -19,6 +18,7 @@ import (
"github.com/distribution/distribution/v3/testutil" "github.com/distribution/distribution/v3/testutil"
"github.com/distribution/reference" "github.com/distribution/reference"
"github.com/opencontainers/go-digest" "github.com/opencontainers/go-digest"
"github.com/opencontainers/image-spec/specs-go"
v1 "github.com/opencontainers/image-spec/specs-go/v1" v1 "github.com/opencontainers/image-spec/specs-go/v1"
) )
@ -94,10 +94,8 @@ func testManifestStorage(t *testing.T, options ...RegistryOption) {
builder := schema2.NewManifestBuilder(d, sampleConfig) builder := schema2.NewManifestBuilder(d, sampleConfig)
m := &schema2.Manifest{ m := &schema2.Manifest{
Versioned: manifest.Versioned{ Versioned: specs.Versioned{SchemaVersion: 2},
SchemaVersion: 2, MediaType: schema2.MediaTypeManifest,
MediaType: schema2.MediaTypeManifest,
},
Config: distribution.Descriptor{ Config: distribution.Descriptor{
Digest: digest.FromBytes(sampleConfig), Digest: digest.FromBytes(sampleConfig),
Size: int64(len(sampleConfig)), Size: int64(len(sampleConfig)),
@ -393,7 +391,7 @@ func testOCIManifestStorage(t *testing.T, testname string, includeMediaTypes boo
t.Fatalf("%s: unexpected MediaType for result, %s", testname, fetchedManifest.MediaType) t.Fatalf("%s: unexpected MediaType for result, %s", testname, fetchedManifest.MediaType)
} }
if fetchedManifest.SchemaVersion != ocischema.SchemaVersion.SchemaVersion { if fetchedManifest.SchemaVersion != 2 {
t.Fatalf("%s: unexpected schema version for result, %d", testname, fetchedManifest.SchemaVersion) t.Fatalf("%s: unexpected schema version for result, %d", testname, fetchedManifest.SchemaVersion)
} }

View file

@ -7,10 +7,10 @@ import (
"testing" "testing"
"github.com/distribution/distribution/v3" "github.com/distribution/distribution/v3"
"github.com/distribution/distribution/v3/manifest"
"github.com/distribution/distribution/v3/manifest/ocischema" "github.com/distribution/distribution/v3/manifest/ocischema"
"github.com/distribution/distribution/v3/registry/storage/driver/inmemory" "github.com/distribution/distribution/v3/registry/storage/driver/inmemory"
"github.com/opencontainers/go-digest" "github.com/opencontainers/go-digest"
"github.com/opencontainers/image-spec/specs-go"
v1 "github.com/opencontainers/image-spec/specs-go/v1" v1 "github.com/opencontainers/image-spec/specs-go/v1"
) )
@ -49,11 +49,9 @@ func TestVerifyOCIManifestNonDistributableLayer(t *testing.T) {
} }
template := ocischema.Manifest{ template := ocischema.Manifest{
Versioned: manifest.Versioned{ Versioned: specs.Versioned{SchemaVersion: 2},
SchemaVersion: 2, MediaType: v1.MediaTypeImageManifest,
MediaType: v1.MediaTypeImageManifest, Config: config,
},
Config: config,
} }
type testcase struct { type testcase struct {
@ -189,10 +187,8 @@ func TestVerifyOCIManifestBlobLayerAndConfig(t *testing.T) {
} }
template := ocischema.Manifest{ template := ocischema.Manifest{
Versioned: manifest.Versioned{ Versioned: specs.Versioned{SchemaVersion: 2},
SchemaVersion: 2, MediaType: v1.MediaTypeImageManifest,
MediaType: v1.MediaTypeImageManifest,
},
} }
checkFn := func(m ocischema.Manifest, rerr error) { checkFn := func(m ocischema.Manifest, rerr error) {

View file

@ -7,10 +7,10 @@ import (
"github.com/distribution/distribution/v3" "github.com/distribution/distribution/v3"
"github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/distribution/v3/internal/dcontext"
"github.com/distribution/distribution/v3/manifest"
"github.com/distribution/distribution/v3/manifest/schema2" "github.com/distribution/distribution/v3/manifest/schema2"
"github.com/distribution/distribution/v3/registry/storage/driver/inmemory" "github.com/distribution/distribution/v3/registry/storage/driver/inmemory"
"github.com/opencontainers/go-digest" "github.com/opencontainers/go-digest"
"github.com/opencontainers/image-spec/specs-go"
) )
func TestVerifyManifestForeignLayer(t *testing.T) { func TestVerifyManifestForeignLayer(t *testing.T) {
@ -45,11 +45,9 @@ func TestVerifyManifestForeignLayer(t *testing.T) {
} }
template := schema2.Manifest{ template := schema2.Manifest{
Versioned: manifest.Versioned{ Versioned: specs.Versioned{SchemaVersion: 2},
SchemaVersion: 2, MediaType: schema2.MediaTypeManifest,
MediaType: schema2.MediaTypeManifest, Config: config,
},
Config: config,
} }
type testcase struct { type testcase struct {
@ -176,10 +174,8 @@ func TestVerifyManifestBlobLayerAndConfig(t *testing.T) {
} }
template := schema2.Manifest{ template := schema2.Manifest{
Versioned: manifest.Versioned{ Versioned: specs.Versioned{SchemaVersion: 2},
SchemaVersion: 2, MediaType: schema2.MediaTypeManifest,
MediaType: schema2.MediaTypeManifest,
},
} }
checkFn := func(m schema2.Manifest, rerr error) { checkFn := func(m schema2.Manifest, rerr error) {

View file

@ -6,11 +6,11 @@ import (
"testing" "testing"
"github.com/distribution/distribution/v3" "github.com/distribution/distribution/v3"
"github.com/distribution/distribution/v3/manifest"
"github.com/distribution/distribution/v3/manifest/schema2" "github.com/distribution/distribution/v3/manifest/schema2"
"github.com/distribution/distribution/v3/registry/storage/driver/inmemory" "github.com/distribution/distribution/v3/registry/storage/driver/inmemory"
"github.com/distribution/reference" "github.com/distribution/reference"
digest "github.com/opencontainers/go-digest" digest "github.com/opencontainers/go-digest"
"github.com/opencontainers/image-spec/specs-go"
) )
type tagsTestEnv struct { type tagsTestEnv struct {
@ -243,10 +243,8 @@ func TestTagIndexes(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
m := schema2.Manifest{ m := schema2.Manifest{
Versioned: manifest.Versioned{ Versioned: specs.Versioned{SchemaVersion: 2},
SchemaVersion: 2, MediaType: schema2.MediaTypeManifest,
MediaType: schema2.MediaTypeManifest,
},
Config: distribution.Descriptor{ Config: distribution.Descriptor{
Digest: conf.Digest, Digest: conf.Digest,
Size: 1, Size: 1,