From 075b3f85dc6e7e49e224080f082dbedc80f4abe9 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sun, 30 Apr 2023 18:16:51 +0200 Subject: [PATCH] deprecate Versioned in favor of oci.Versioned Update the Manifest types to use the oci implementation of the Versioned struct. Signed-off-by: Sebastiaan van Stijn --- manifest/manifestlist/manifestlist.go | 24 ++++++++--- manifest/ocischema/builder.go | 8 ++-- manifest/ocischema/index.go | 12 +++--- manifest/ocischema/manifest.go | 13 ++++-- manifest/ocischema/manifest_test.go | 8 ++-- manifest/schema1/config_builder.go | 6 +-- manifest/schema1/manifest.go | 8 ++-- manifest/schema1/reference_builder.go | 6 +-- manifest/schema1/reference_builder_test.go | 6 +-- manifest/schema2/builder.go | 4 +- manifest/schema2/manifest.go | 26 ++++++++---- manifest/schema2/manifest_test.go | 8 ++-- manifest/versioned.go | 2 + notifications/listener_test.go | 4 +- registry/client/repository_test.go | 5 +-- registry/handlers/api_test.go | 42 +++++++------------ registry/proxy/proxymanifeststore_test.go | 4 +- registry/storage/manifeststore_test.go | 12 +++--- registry/storage/ocimanifesthandler_test.go | 16 +++---- .../storage/schema2manifesthandler_test.go | 16 +++---- registry/storage/tagstore_test.go | 8 ++-- testutil/manifests.go | 10 ++--- 22 files changed, 124 insertions(+), 124 deletions(-) diff --git a/manifest/manifestlist/manifestlist.go b/manifest/manifestlist/manifestlist.go index 25ffbe525..122669415 100644 --- a/manifest/manifestlist/manifestlist.go +++ b/manifest/manifestlist/manifestlist.go @@ -8,6 +8,7 @@ import ( "github.com/distribution/distribution/v3" "github.com/distribution/distribution/v3/manifest" "github.com/opencontainers/go-digest" + "github.com/opencontainers/image-spec/specs-go" v1 "github.com/opencontainers/image-spec/specs-go/v1" ) @@ -18,6 +19,9 @@ const ( // SchemaVersion provides a pre-initialized version structure for this // packages version of the manifest. +// +// Deprecated: use [specs.Versioned] and set MediaType on the manifest +// to [MediaTypeManifestList]. var SchemaVersion = manifest.Versioned{ SchemaVersion: 2, MediaType: MediaTypeManifestList, @@ -85,7 +89,10 @@ type ManifestDescriptor struct { // ManifestList references manifests for various platforms. 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 []ManifestDescriptor `json:"manifests"` @@ -128,10 +135,8 @@ func FromDescriptors(descriptors []ManifestDescriptor) (*DeserializedManifestLis // 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) { m := ManifestList{ - Versioned: manifest.Versioned{ - SchemaVersion: SchemaVersion.SchemaVersion, - MediaType: mediaType, - }, + Versioned: specs.Versioned{SchemaVersion: 2}, + MediaType: mediaType, } m.Manifests = make([]ManifestDescriptor, len(descriptors)) @@ -176,7 +181,14 @@ func (m *DeserializedManifestList) MarshalJSON() ([]byte, error) { // Payload returns the raw content of the manifest list. The contents can be // used to calculate the content identifier. 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 diff --git a/manifest/ocischema/builder.go b/manifest/ocischema/builder.go index 7d99c184f..0473c4ef6 100644 --- a/manifest/ocischema/builder.go +++ b/manifest/ocischema/builder.go @@ -5,8 +5,8 @@ import ( "errors" "github.com/distribution/distribution/v3" - "github.com/distribution/distribution/v3/manifest" "github.com/opencontainers/go-digest" + "github.com/opencontainers/image-spec/specs-go" 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. func (mb *Builder) Build(ctx context.Context) (distribution.Manifest, error) { m := Manifest{ - Versioned: manifest.Versioned{ - SchemaVersion: 2, - MediaType: mb.mediaType, - }, + Versioned: specs.Versioned{SchemaVersion: 2}, + MediaType: mb.mediaType, Layers: make([]distribution.Descriptor, len(mb.layers)), Annotations: mb.annotations, } diff --git a/manifest/ocischema/index.go b/manifest/ocischema/index.go index 3ae824f40..a1c91a607 100644 --- a/manifest/ocischema/index.go +++ b/manifest/ocischema/index.go @@ -8,6 +8,7 @@ import ( "github.com/distribution/distribution/v3" "github.com/distribution/distribution/v3/manifest" "github.com/opencontainers/go-digest" + "github.com/opencontainers/image-spec/specs-go" v1 "github.com/opencontainers/image-spec/specs-go/v1" ) @@ -47,7 +48,10 @@ func init() { // ImageIndex references manifests for various platforms. 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 []distribution.Descriptor `json:"manifests"` @@ -83,10 +87,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 func fromDescriptorsWithMediaType(descriptors []distribution.Descriptor, annotations map[string]string, mediaType string) (_ *DeserializedImageIndex, err error) { m := ImageIndex{ - Versioned: manifest.Versioned{ - SchemaVersion: IndexSchemaVersion.SchemaVersion, - MediaType: mediaType, - }, + Versioned: specs.Versioned{SchemaVersion: 2}, + MediaType: mediaType, Annotations: annotations, } diff --git a/manifest/ocischema/manifest.go b/manifest/ocischema/manifest.go index 973cd64ae..acfbf7210 100644 --- a/manifest/ocischema/manifest.go +++ b/manifest/ocischema/manifest.go @@ -8,11 +8,15 @@ import ( "github.com/distribution/distribution/v3" "github.com/distribution/distribution/v3/manifest" "github.com/opencontainers/go-digest" + "github.com/opencontainers/image-spec/specs-go" v1 "github.com/opencontainers/image-spec/specs-go/v1" ) // 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]. var SchemaVersion = manifest.Versioned{ SchemaVersion: 2, MediaType: v1.MediaTypeImageManifest, @@ -40,7 +44,10 @@ func init() { // Manifest defines a ocischema manifest. 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 distribution.Descriptor `json:"config"` @@ -120,7 +127,7 @@ func (m *DeserializedManifest) MarshalJSON() ([]byte, error) { // Payload returns the raw content of the manifest. The contents can be used to // calculate the content identifier. -func (m DeserializedManifest) Payload() (string, []byte, error) { +func (m *DeserializedManifest) Payload() (string, []byte, error) { return v1.MediaTypeImageManifest, m.canonical, nil } diff --git a/manifest/ocischema/manifest_test.go b/manifest/ocischema/manifest_test.go index 7cde85a31..1d36230d8 100644 --- a/manifest/ocischema/manifest_test.go +++ b/manifest/ocischema/manifest_test.go @@ -7,8 +7,8 @@ import ( "testing" "github.com/distribution/distribution/v3" - "github.com/distribution/distribution/v3/manifest" "github.com/distribution/distribution/v3/manifest/manifestlist" + "github.com/opencontainers/image-spec/specs-go" v1 "github.com/opencontainers/image-spec/specs-go/v1" ) @@ -41,10 +41,8 @@ const expectedManifestSerialization = `{ func makeTestManifest(mediaType string) Manifest { return Manifest{ - Versioned: manifest.Versioned{ - SchemaVersion: 2, - MediaType: mediaType, - }, + Versioned: specs.Versioned{SchemaVersion: 2}, + MediaType: mediaType, Config: distribution.Descriptor{ MediaType: v1.MediaTypeImageConfig, Digest: "sha256:1a9ec845ee94c202b2d5da74a24f0ed2058318bfa9879fa541efaecba272e86b", diff --git a/manifest/schema1/config_builder.go b/manifest/schema1/config_builder.go index 77fdfee99..ff0a8b44f 100644 --- a/manifest/schema1/config_builder.go +++ b/manifest/schema1/config_builder.go @@ -9,10 +9,10 @@ import ( "time" "github.com/distribution/distribution/v3" - "github.com/distribution/distribution/v3/manifest" "github.com/distribution/distribution/v3/reference" "github.com/docker/libtrust" "github.com/opencontainers/go-digest" + "github.com/opencontainers/image-spec/specs-go" ) type diffID digest.Digest @@ -202,9 +202,7 @@ func (mb *configManifestBuilder) Build(ctx context.Context) (m distribution.Mani } mfst := Manifest{ - Versioned: manifest.Versioned{ - SchemaVersion: 1, - }, + Versioned: specs.Versioned{SchemaVersion: 1}, Name: mb.ref.Name(), Tag: tag, Architecture: img.Architecture, diff --git a/manifest/schema1/manifest.go b/manifest/schema1/manifest.go index 4faee15d8..fc170d9d8 100644 --- a/manifest/schema1/manifest.go +++ b/manifest/schema1/manifest.go @@ -11,9 +11,9 @@ import ( "fmt" "github.com/distribution/distribution/v3" - "github.com/distribution/distribution/v3/manifest" "github.com/docker/libtrust" "github.com/opencontainers/go-digest" + "github.com/opencontainers/image-spec/specs-go" ) // MediaTypeManifest specifies the mediaType for the current version. Note @@ -40,9 +40,7 @@ const MediaTypeManifestLayer = "application/vnd.docker.container.image.rootfs.di // // Deprecated: Docker Image Manifest v2, Schema 1 is deprecated since 2015. // Use Docker Image Manifest v2, Schema 2, or the OCI Image Specification. -var SchemaVersion = manifest.Versioned{ - SchemaVersion: 1, -} +var SchemaVersion = specs.Versioned{SchemaVersion: 1} func init() { schema1Func := func(b []byte) (distribution.Manifest, distribution.Descriptor, error) { @@ -97,7 +95,7 @@ type History struct { // Deprecated: Docker Image Manifest v2, Schema 1 is deprecated since 2015. // Use Docker Image Manifest v2, Schema 2, or the OCI Image Specification. type Manifest struct { - manifest.Versioned + specs.Versioned // Name is the name of the image's repository Name string `json:"name"` diff --git a/manifest/schema1/reference_builder.go b/manifest/schema1/reference_builder.go index 13713b527..78d9853e7 100644 --- a/manifest/schema1/reference_builder.go +++ b/manifest/schema1/reference_builder.go @@ -6,10 +6,10 @@ import ( "fmt" "github.com/distribution/distribution/v3" - "github.com/distribution/distribution/v3/manifest" "github.com/distribution/distribution/v3/reference" "github.com/docker/libtrust" "github.com/opencontainers/go-digest" + "github.com/opencontainers/image-spec/specs-go" ) // referenceManifestBuilder is a type for constructing manifests from schema1 @@ -32,9 +32,7 @@ func NewReferenceManifestBuilder(pk libtrust.PrivateKey, ref reference.Named, ar return &referenceManifestBuilder{ Manifest: Manifest{ - Versioned: manifest.Versioned{ - SchemaVersion: 1, - }, + Versioned: specs.Versioned{SchemaVersion: 1}, Name: ref.Name(), Tag: tag, Architecture: architecture, diff --git a/manifest/schema1/reference_builder_test.go b/manifest/schema1/reference_builder_test.go index 31fde6468..7aec30b2d 100644 --- a/manifest/schema1/reference_builder_test.go +++ b/manifest/schema1/reference_builder_test.go @@ -4,17 +4,15 @@ import ( "testing" "github.com/distribution/distribution/v3/context" - "github.com/distribution/distribution/v3/manifest" "github.com/distribution/distribution/v3/reference" "github.com/docker/libtrust" "github.com/opencontainers/go-digest" + "github.com/opencontainers/image-spec/specs-go" ) func makeSignedManifest(t *testing.T, pk libtrust.PrivateKey, refs []Reference) *SignedManifest { u := &Manifest{ - Versioned: manifest.Versioned{ - SchemaVersion: 1, - }, + Versioned: specs.Versioned{SchemaVersion: 1}, Name: "foo/bar", Tag: "latest", Architecture: "amd64", diff --git a/manifest/schema2/builder.go b/manifest/schema2/builder.go index 585741d03..e00bbd06a 100644 --- a/manifest/schema2/builder.go +++ b/manifest/schema2/builder.go @@ -4,6 +4,7 @@ import ( "context" "github.com/distribution/distribution/v3" + "github.com/opencontainers/image-spec/specs-go" ) // 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. func (mb *builder) Build(ctx context.Context) (distribution.Manifest, error) { m := Manifest{ - Versioned: SchemaVersion, + Versioned: specs.Versioned{SchemaVersion: defaultSchemaVersion}, + MediaType: defaultMediaType, Layers: make([]distribution.Descriptor, len(mb.dependencies)), } copy(m.Layers, mb.dependencies) diff --git a/manifest/schema2/manifest.go b/manifest/schema2/manifest.go index 89bf63c96..54a177b7f 100644 --- a/manifest/schema2/manifest.go +++ b/manifest/schema2/manifest.go @@ -8,6 +8,7 @@ import ( "github.com/distribution/distribution/v3" "github.com/distribution/distribution/v3/manifest" "github.com/opencontainers/go-digest" + "github.com/opencontainers/image-spec/specs-go" ) const ( @@ -33,11 +34,19 @@ const ( MediaTypeUncompressedLayer = "application/vnd.docker.image.rootfs.diff.tar" ) +const ( + defaultSchemaVersion = 2 + defaultMediaType = MediaTypeManifest +) + // SchemaVersion provides a pre-initialized version structure for this // packages version of the manifest. +// +// Deprecated: use [specs.Versioned] and set MediaType on the manifest +// to [MediaTypeManifest]. var SchemaVersion = manifest.Versioned{ - SchemaVersion: 2, - MediaType: MediaTypeManifest, + SchemaVersion: defaultSchemaVersion, + MediaType: defaultMediaType, } func init() { @@ -49,9 +58,9 @@ func init() { } dgst := digest.FromBytes(b) - return m, distribution.Descriptor{Digest: dgst, Size: int64(len(b)), MediaType: MediaTypeManifest}, err + return m, distribution.Descriptor{Digest: dgst, Size: int64(len(b)), MediaType: defaultMediaType}, err } - err := distribution.RegisterManifestSchema(MediaTypeManifest, schema2Func) + err := distribution.RegisterManifestSchema(defaultMediaType, schema2Func) if err != nil { panic(fmt.Sprintf("Unable to register manifest: %s", err)) } @@ -59,7 +68,10 @@ func init() { // Manifest defines a schema2 manifest. 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 distribution.Descriptor `json:"config"` @@ -114,9 +126,9 @@ func (m *DeserializedManifest) UnmarshalJSON(b []byte) error { return err } - if mfst.MediaType != MediaTypeManifest { + if mfst.MediaType != defaultMediaType { return fmt.Errorf("mediaType in manifest should be '%s' not '%s'", - MediaTypeManifest, mfst.MediaType) + defaultMediaType, mfst.MediaType) } m.Manifest = mfst diff --git a/manifest/schema2/manifest_test.go b/manifest/schema2/manifest_test.go index 23d69f032..7e2c18c9b 100644 --- a/manifest/schema2/manifest_test.go +++ b/manifest/schema2/manifest_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/distribution/distribution/v3" - "github.com/distribution/distribution/v3/manifest" + "github.com/opencontainers/image-spec/specs-go" ) const expectedManifestSerialization = `{ @@ -29,10 +29,8 @@ const expectedManifestSerialization = `{ func makeTestManifest(mediaType string) Manifest { return Manifest{ - Versioned: manifest.Versioned{ - SchemaVersion: 2, - MediaType: mediaType, - }, + Versioned: specs.Versioned{SchemaVersion: 2}, + MediaType: mediaType, Config: distribution.Descriptor{ MediaType: MediaTypeImageConfig, Digest: "sha256:1a9ec845ee94c202b2d5da74a24f0ed2058318bfa9879fa541efaecba272e86b", diff --git a/manifest/versioned.go b/manifest/versioned.go index caa6b14e8..ec8ebc557 100644 --- a/manifest/versioned.go +++ b/manifest/versioned.go @@ -3,6 +3,8 @@ package manifest // Versioned provides a struct with the manifest schemaVersion and mediaType. // Incoming content with unknown schema version can be decoded against this // struct to check the version. +// +// Deprecated: use [specs.Versioned] and set MediaType on the Manifest itself. type Versioned struct { // SchemaVersion is the image manifest schema that this image follows SchemaVersion int `json:"schemaVersion"` diff --git a/notifications/listener_test.go b/notifications/listener_test.go index 8d0c18a49..4bc9f9ff4 100644 --- a/notifications/listener_test.go +++ b/notifications/listener_test.go @@ -14,6 +14,7 @@ import ( "github.com/distribution/distribution/v3/registry/storage/driver/inmemory" "github.com/distribution/distribution/v3/testutil" "github.com/opencontainers/go-digest" + "github.com/opencontainers/image-spec/specs-go" ) func TestListener(t *testing.T) { @@ -143,7 +144,8 @@ func checkTestRepository(t *testing.T, repository distribution.Repository, remov } m := schema2.Manifest{ - Versioned: schema2.SchemaVersion, + Versioned: specs.Versioned{SchemaVersion: 2}, + MediaType: schema2.MediaTypeManifest, Config: distribution.Descriptor{ MediaType: "foo/bar", Digest: configDgst, diff --git a/registry/client/repository_test.go b/registry/client/repository_test.go index 7681bf869..1cc3dd146 100644 --- a/registry/client/repository_test.go +++ b/registry/client/repository_test.go @@ -18,7 +18,6 @@ import ( "github.com/distribution/distribution/v3" "github.com/distribution/distribution/v3/context" - "github.com/distribution/distribution/v3/manifest" "github.com/distribution/distribution/v3/manifest/schema1" //nolint:staticcheck // Ignore SA1019: "github.com/distribution/distribution/v3/manifest/schema1" is deprecated, as it's used for backward compatibility. "github.com/distribution/distribution/v3/reference" "github.com/distribution/distribution/v3/registry/api/errcode" @@ -934,9 +933,7 @@ func newRandomSchemaV1Manifest(name reference.Named, tag string, blobCount int) Architecture: "x86", FSLayers: blobs, History: history, - Versioned: manifest.Versioned{ - SchemaVersion: 1, - }, + Versioned: schema1.SchemaVersion, //nolint:staticcheck // Ignore SA1019: "github.com/distribution/distribution/v3/manifest/schema1" is deprecated, as it's used for backward compatibility. } pk, err := libtrust.GenerateECP256PrivateKey() diff --git a/registry/handlers/api_test.go b/registry/handlers/api_test.go index 5fd1790c1..3c1302915 100644 --- a/registry/handlers/api_test.go +++ b/registry/handlers/api_test.go @@ -21,7 +21,6 @@ import ( "github.com/distribution/distribution/v3" "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/schema1" //nolint:staticcheck // Ignore SA1019: "github.com/distribution/distribution/v3/manifest/schema1" is deprecated, as it's used for backward compatibility. "github.com/distribution/distribution/v3/manifest/schema2" @@ -35,6 +34,7 @@ import ( "github.com/docker/libtrust" "github.com/gorilla/handlers" "github.com/opencontainers/go-digest" + "github.com/opencontainers/image-spec/specs-go" ) var headerConfig = http.Header{ @@ -1532,11 +1532,9 @@ func testManifestAPISchema1(t *testing.T, env *testEnv, imageName reference.Name // -------------------------------- // Attempt to push unsigned manifest with missing layers unsignedManifest := &schema1.Manifest{ //nolint:staticcheck // Ignore SA1019: "github.com/distribution/distribution/v3/manifest/schema1" is deprecated, as it's used for backward compatibility. - Versioned: manifest.Versioned{ - SchemaVersion: 1, - }, - Name: imageName.Name(), - Tag: tag, + Versioned: schema1.SchemaVersion, //nolint:staticcheck // Ignore SA1019: "github.com/distribution/distribution/v3/manifest/schema1" is deprecated, as it's used for backward compatibility. + Name: imageName.Name(), + Tag: tag, FSLayers: []schema1.FSLayer{ //nolint:staticcheck // Ignore SA1019: "github.com/distribution/distribution/v3/manifest/schema1" is deprecated, as it's used for backward compatibility. { BlobSum: "asdf", @@ -1851,10 +1849,8 @@ func testManifestAPISchema2(t *testing.T, env *testEnv, imageName reference.Name // -------------------------------- // Attempt to push manifest with missing config and missing layers manifest := &schema2.Manifest{ - Versioned: manifest.Versioned{ - SchemaVersion: 2, - MediaType: schema2.MediaTypeManifest, - }, + Versioned: specs.Versioned{SchemaVersion: 2}, + MediaType: schema2.MediaTypeManifest, Config: distribution.Descriptor{ Digest: "sha256:1a9ec845ee94c202b2d5da74a24f0ed2058318bfa9879fa541efaecba272e86b", Size: 3253, @@ -2174,10 +2170,8 @@ func testManifestAPIManifestList(t *testing.T, env *testEnv, args manifestArgs) // -------------------------------- // Attempt to push manifest list that refers to an unknown manifest manifestList := &manifestlist.ManifestList{ - Versioned: manifest.Versioned{ - SchemaVersion: 2, - MediaType: manifestlist.MediaTypeManifestList, - }, + Versioned: specs.Versioned{SchemaVersion: 2}, + MediaType: manifestlist.MediaTypeManifestList, Manifests: []manifestlist.ManifestDescriptor{ { Descriptor: distribution.Descriptor{ @@ -2969,11 +2963,9 @@ func createRepository(env *testEnv, t *testing.T, imageName string, tag string) } unsignedManifest := &schema1.Manifest{ //nolint:staticcheck // Ignore SA1019: "github.com/distribution/distribution/v3/manifest/schema1" is deprecated, as it's used for backward compatibility. - Versioned: manifest.Versioned{ - SchemaVersion: 1, - }, - Name: imageName, - Tag: tag, + Versioned: schema1.SchemaVersion, //nolint:staticcheck // Ignore SA1019: "github.com/distribution/distribution/v3/manifest/schema1" is deprecated, as it's used for backward compatibility. + Name: imageName, + Tag: tag, FSLayers: []schema1.FSLayer{ //nolint:staticcheck // Ignore SA1019: "github.com/distribution/distribution/v3/manifest/schema1" is deprecated, as it's used for backward compatibility. { BlobSum: "asdf", @@ -3043,13 +3035,11 @@ func TestRegistryAsCacheMutationAPIs(t *testing.T) { // Manifest upload m := &schema1.Manifest{ //nolint:staticcheck // Ignore SA1019: "github.com/distribution/distribution/v3/manifest/schema1" is deprecated, as it's used for backward compatibility. - Versioned: manifest.Versioned{ - SchemaVersion: 1, - }, - Name: imageName.Name(), - Tag: tag, - FSLayers: []schema1.FSLayer{}, //nolint:staticcheck // Ignore SA1019: "github.com/distribution/distribution/v3/manifest/schema1" is deprecated, as it's used for backward compatibility. - History: []schema1.History{}, //nolint:staticcheck // Ignore SA1019: "github.com/distribution/distribution/v3/manifest/schema1" is deprecated, as it's used for backward compatibility. + Versioned: schema1.SchemaVersion, //nolint:staticcheck // Ignore SA1019: "github.com/distribution/distribution/v3/manifest/schema1" is deprecated, as it's used for backward compatibility. + Name: imageName.Name(), + Tag: tag, + FSLayers: []schema1.FSLayer{}, //nolint:staticcheck // Ignore SA1019: "github.com/distribution/distribution/v3/manifest/schema1" is deprecated, as it's used for backward compatibility. + History: []schema1.History{}, //nolint:staticcheck // Ignore SA1019: "github.com/distribution/distribution/v3/manifest/schema1" is deprecated, as it's used for backward compatibility. } sm, err := schema1.Sign(m, env.pk) //nolint:staticcheck // Ignore SA1019: "github.com/distribution/distribution/v3/manifest/schema1" is deprecated, as it's used for backward compatibility. diff --git a/registry/proxy/proxymanifeststore_test.go b/registry/proxy/proxymanifeststore_test.go index bd1c7ad9a..032de3fde 100644 --- a/registry/proxy/proxymanifeststore_test.go +++ b/registry/proxy/proxymanifeststore_test.go @@ -17,6 +17,7 @@ import ( "github.com/distribution/distribution/v3/registry/storage/driver/inmemory" "github.com/distribution/distribution/v3/testutil" "github.com/opencontainers/go-digest" + "github.com/opencontainers/image-spec/specs-go" ) type statsManifest struct { @@ -153,7 +154,8 @@ func populateRepo(ctx context.Context, t *testing.T, repository distribution.Rep } m := schema2.Manifest{ - Versioned: schema2.SchemaVersion, + Versioned: specs.Versioned{SchemaVersion: 2}, + MediaType: schema2.MediaTypeManifest, Config: distribution.Descriptor{ MediaType: "foo/bar", Digest: configDigest, diff --git a/registry/storage/manifeststore_test.go b/registry/storage/manifeststore_test.go index d40315a9f..96dd339b9 100644 --- a/registry/storage/manifeststore_test.go +++ b/registry/storage/manifeststore_test.go @@ -9,7 +9,6 @@ import ( "testing" "github.com/distribution/distribution/v3" - "github.com/distribution/distribution/v3/manifest" "github.com/distribution/distribution/v3/manifest/ocischema" "github.com/distribution/distribution/v3/manifest/schema1" //nolint:staticcheck // Ignore SA1019: "github.com/distribution/distribution/v3/manifest/schema1" is deprecated, as it's used for backward compatibility. "github.com/distribution/distribution/v3/reference" @@ -19,6 +18,7 @@ import ( "github.com/distribution/distribution/v3/testutil" "github.com/docker/libtrust" "github.com/opencontainers/go-digest" + "github.com/opencontainers/image-spec/specs-go" v1 "github.com/opencontainers/image-spec/specs-go/v1" ) @@ -80,11 +80,9 @@ func testManifestStorage(t *testing.T, schema1Enabled bool, options ...RegistryO } m := schema1.Manifest{ //nolint:staticcheck // Ignore SA1019: "github.com/distribution/distribution/v3/manifest/schema1" is deprecated, as it's used for backward compatibility. - Versioned: manifest.Versioned{ - SchemaVersion: 1, - }, - Name: env.name.Name(), - Tag: env.tag, + Versioned: specs.Versioned{SchemaVersion: 1}, + Name: env.name.Name(), + Tag: env.tag, } // Build up some test layers and add them to the manifest, saving the @@ -495,7 +493,7 @@ func testOCIManifestStorage(t *testing.T, testname string, includeMediaTypes boo 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) } diff --git a/registry/storage/ocimanifesthandler_test.go b/registry/storage/ocimanifesthandler_test.go index 5eab9b9f6..dae683c27 100644 --- a/registry/storage/ocimanifesthandler_test.go +++ b/registry/storage/ocimanifesthandler_test.go @@ -7,10 +7,10 @@ import ( "testing" "github.com/distribution/distribution/v3" - "github.com/distribution/distribution/v3/manifest" "github.com/distribution/distribution/v3/manifest/ocischema" "github.com/distribution/distribution/v3/registry/storage/driver/inmemory" "github.com/opencontainers/go-digest" + "github.com/opencontainers/image-spec/specs-go" v1 "github.com/opencontainers/image-spec/specs-go/v1" ) @@ -49,11 +49,9 @@ func TestVerifyOCIManifestNonDistributableLayer(t *testing.T) { } template := ocischema.Manifest{ - Versioned: manifest.Versioned{ - SchemaVersion: 2, - MediaType: v1.MediaTypeImageManifest, - }, - Config: config, + Versioned: specs.Versioned{SchemaVersion: 2}, + MediaType: v1.MediaTypeImageManifest, + Config: config, } type testcase struct { @@ -189,10 +187,8 @@ func TestVerifyOCIManifestBlobLayerAndConfig(t *testing.T) { } template := ocischema.Manifest{ - Versioned: manifest.Versioned{ - SchemaVersion: 2, - MediaType: v1.MediaTypeImageManifest, - }, + Versioned: specs.Versioned{SchemaVersion: 2}, + MediaType: v1.MediaTypeImageManifest, } checkFn := func(m ocischema.Manifest, rerr error) { diff --git a/registry/storage/schema2manifesthandler_test.go b/registry/storage/schema2manifesthandler_test.go index 908f8c137..20fefa7d7 100644 --- a/registry/storage/schema2manifesthandler_test.go +++ b/registry/storage/schema2manifesthandler_test.go @@ -7,10 +7,10 @@ import ( "github.com/distribution/distribution/v3" "github.com/distribution/distribution/v3/context" - "github.com/distribution/distribution/v3/manifest" "github.com/distribution/distribution/v3/manifest/schema2" "github.com/distribution/distribution/v3/registry/storage/driver/inmemory" "github.com/opencontainers/go-digest" + "github.com/opencontainers/image-spec/specs-go" ) func TestVerifyManifestForeignLayer(t *testing.T) { @@ -43,11 +43,9 @@ func TestVerifyManifestForeignLayer(t *testing.T) { } template := schema2.Manifest{ - Versioned: manifest.Versioned{ - SchemaVersion: 2, - MediaType: schema2.MediaTypeManifest, - }, - Config: config, + Versioned: specs.Versioned{SchemaVersion: 2}, + MediaType: schema2.MediaTypeManifest, + Config: config, } type testcase struct { @@ -172,10 +170,8 @@ func TestVerifyManifestBlobLayerAndConfig(t *testing.T) { } template := schema2.Manifest{ - Versioned: manifest.Versioned{ - SchemaVersion: 2, - MediaType: schema2.MediaTypeManifest, - }, + Versioned: specs.Versioned{SchemaVersion: 2}, + MediaType: schema2.MediaTypeManifest, } checkFn := func(m schema2.Manifest, rerr error) { diff --git a/registry/storage/tagstore_test.go b/registry/storage/tagstore_test.go index 650416c10..ba5b026b8 100644 --- a/registry/storage/tagstore_test.go +++ b/registry/storage/tagstore_test.go @@ -6,11 +6,11 @@ import ( "testing" "github.com/distribution/distribution/v3" - "github.com/distribution/distribution/v3/manifest" "github.com/distribution/distribution/v3/manifest/schema2" "github.com/distribution/distribution/v3/reference" "github.com/distribution/distribution/v3/registry/storage/driver/inmemory" digest "github.com/opencontainers/go-digest" + "github.com/opencontainers/image-spec/specs-go" ) type tagsTestEnv struct { @@ -243,10 +243,8 @@ func TestTagIndexes(t *testing.T) { t.Fatal(err) } m := schema2.Manifest{ - Versioned: manifest.Versioned{ - SchemaVersion: 2, - MediaType: schema2.MediaTypeManifest, - }, + Versioned: specs.Versioned{SchemaVersion: 2}, + MediaType: schema2.MediaTypeManifest, Config: distribution.Descriptor{ Digest: conf.Digest, Size: 1, diff --git a/testutil/manifests.go b/testutil/manifests.go index 3a6a333b5..c9643f4f8 100644 --- a/testutil/manifests.go +++ b/testutil/manifests.go @@ -5,12 +5,12 @@ import ( "github.com/distribution/distribution/v3" "github.com/distribution/distribution/v3/context" - "github.com/distribution/distribution/v3/manifest" "github.com/distribution/distribution/v3/manifest/manifestlist" "github.com/distribution/distribution/v3/manifest/schema1" //nolint:staticcheck // Ignore SA1019: "github.com/distribution/distribution/v3/manifest/schema1" is deprecated, as it's used for backward compatibility. "github.com/distribution/distribution/v3/manifest/schema2" "github.com/docker/libtrust" "github.com/opencontainers/go-digest" + "github.com/opencontainers/image-spec/specs-go" ) // MakeManifestList constructs a manifest list out of a list of manifest digests @@ -46,11 +46,9 @@ func MakeManifestList(blobstatter distribution.BlobStatter, manifestDigests []di // Use Docker Image Manifest v2, Schema 2, or the OCI Image Specification. func MakeSchema1Manifest(digests []digest.Digest) (*schema1.SignedManifest, error) { mfst := schema1.Manifest{ - Versioned: manifest.Versioned{ - SchemaVersion: 1, - }, - Name: "who", - Tag: "cares", + Versioned: specs.Versioned{SchemaVersion: 1}, + Name: "who", + Tag: "cares", } for _, d := range digests {