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 <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-04-30 18:16:51 +02:00
parent 1813dd13b4
commit 075b3f85dc
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
22 changed files with 124 additions and 124 deletions

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,9 @@ 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].
var SchemaVersion = manifest.Versioned{ var SchemaVersion = manifest.Versioned{
SchemaVersion: 2, SchemaVersion: 2,
MediaType: MediaTypeManifestList, MediaType: MediaTypeManifestList,
@ -85,7 +89,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"`
@ -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 // 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))
@ -176,7 +181,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,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"
) )
@ -47,7 +48,10 @@ func init() {
// 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"`
@ -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 // 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,15 @@ 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].
var SchemaVersion = manifest.Versioned{ var SchemaVersion = manifest.Versioned{
SchemaVersion: 2, SchemaVersion: 2,
MediaType: v1.MediaTypeImageManifest, MediaType: v1.MediaTypeImageManifest,
@ -40,7 +44,10 @@ func init() {
// 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"`
@ -120,7 +127,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"
v1 "github.com/opencontainers/image-spec/specs-go/v1" v1 "github.com/opencontainers/image-spec/specs-go/v1"
) )
@ -41,10 +41,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

@ -9,10 +9,10 @@ import (
"time" "time"
"github.com/distribution/distribution/v3" "github.com/distribution/distribution/v3"
"github.com/distribution/distribution/v3/manifest"
"github.com/distribution/distribution/v3/reference" "github.com/distribution/distribution/v3/reference"
"github.com/docker/libtrust" "github.com/docker/libtrust"
"github.com/opencontainers/go-digest" "github.com/opencontainers/go-digest"
"github.com/opencontainers/image-spec/specs-go"
) )
type diffID digest.Digest type diffID digest.Digest
@ -202,9 +202,7 @@ func (mb *configManifestBuilder) Build(ctx context.Context) (m distribution.Mani
} }
mfst := Manifest{ mfst := Manifest{
Versioned: manifest.Versioned{ Versioned: specs.Versioned{SchemaVersion: 1},
SchemaVersion: 1,
},
Name: mb.ref.Name(), Name: mb.ref.Name(),
Tag: tag, Tag: tag,
Architecture: img.Architecture, Architecture: img.Architecture,

View file

@ -11,9 +11,9 @@ import (
"fmt" "fmt"
"github.com/distribution/distribution/v3" "github.com/distribution/distribution/v3"
"github.com/distribution/distribution/v3/manifest"
"github.com/docker/libtrust" "github.com/docker/libtrust"
"github.com/opencontainers/go-digest" "github.com/opencontainers/go-digest"
"github.com/opencontainers/image-spec/specs-go"
) )
// MediaTypeManifest specifies the mediaType for the current version. Note // 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. // Deprecated: Docker Image Manifest v2, Schema 1 is deprecated since 2015.
// Use Docker Image Manifest v2, Schema 2, or the OCI Image Specification. // Use Docker Image Manifest v2, Schema 2, or the OCI Image Specification.
var SchemaVersion = manifest.Versioned{ var SchemaVersion = specs.Versioned{SchemaVersion: 1}
SchemaVersion: 1,
}
func init() { func init() {
schema1Func := func(b []byte) (distribution.Manifest, distribution.Descriptor, error) { 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. // Deprecated: Docker Image Manifest v2, Schema 1 is deprecated since 2015.
// Use Docker Image Manifest v2, Schema 2, or the OCI Image Specification. // Use Docker Image Manifest v2, Schema 2, or the OCI Image Specification.
type Manifest struct { type Manifest struct {
manifest.Versioned specs.Versioned
// Name is the name of the image's repository // Name is the name of the image's repository
Name string `json:"name"` Name string `json:"name"`

View file

@ -6,10 +6,10 @@ import (
"fmt" "fmt"
"github.com/distribution/distribution/v3" "github.com/distribution/distribution/v3"
"github.com/distribution/distribution/v3/manifest"
"github.com/distribution/distribution/v3/reference" "github.com/distribution/distribution/v3/reference"
"github.com/docker/libtrust" "github.com/docker/libtrust"
"github.com/opencontainers/go-digest" "github.com/opencontainers/go-digest"
"github.com/opencontainers/image-spec/specs-go"
) )
// referenceManifestBuilder is a type for constructing manifests from schema1 // referenceManifestBuilder is a type for constructing manifests from schema1
@ -32,9 +32,7 @@ func NewReferenceManifestBuilder(pk libtrust.PrivateKey, ref reference.Named, ar
return &referenceManifestBuilder{ return &referenceManifestBuilder{
Manifest: Manifest{ Manifest: Manifest{
Versioned: manifest.Versioned{ Versioned: specs.Versioned{SchemaVersion: 1},
SchemaVersion: 1,
},
Name: ref.Name(), Name: ref.Name(),
Tag: tag, Tag: tag,
Architecture: architecture, Architecture: architecture,

View file

@ -4,17 +4,15 @@ import (
"testing" "testing"
"github.com/distribution/distribution/v3/context" "github.com/distribution/distribution/v3/context"
"github.com/distribution/distribution/v3/manifest"
"github.com/distribution/distribution/v3/reference" "github.com/distribution/distribution/v3/reference"
"github.com/docker/libtrust" "github.com/docker/libtrust"
"github.com/opencontainers/go-digest" "github.com/opencontainers/go-digest"
"github.com/opencontainers/image-spec/specs-go"
) )
func makeSignedManifest(t *testing.T, pk libtrust.PrivateKey, refs []Reference) *SignedManifest { func makeSignedManifest(t *testing.T, pk libtrust.PrivateKey, refs []Reference) *SignedManifest {
u := &Manifest{ u := &Manifest{
Versioned: manifest.Versioned{ Versioned: specs.Versioned{SchemaVersion: 1},
SchemaVersion: 1,
},
Name: "foo/bar", Name: "foo/bar",
Tag: "latest", Tag: "latest",
Architecture: "amd64", Architecture: "amd64",

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,11 +34,19 @@ 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].
var SchemaVersion = manifest.Versioned{ var SchemaVersion = manifest.Versioned{
SchemaVersion: 2, SchemaVersion: defaultSchemaVersion,
MediaType: MediaTypeManifest, MediaType: defaultMediaType,
} }
func init() { func init() {
@ -49,9 +58,9 @@ func init() {
} }
dgst := digest.FromBytes(b) 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 { if err != nil {
panic(fmt.Sprintf("Unable to register manifest: %s", err)) panic(fmt.Sprintf("Unable to register manifest: %s", err))
} }
@ -59,7 +68,10 @@ func init() {
// 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"`
@ -114,9 +126,9 @@ 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'",
MediaTypeManifest, mfst.MediaType) defaultMediaType, 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

@ -14,6 +14,7 @@ import (
"github.com/distribution/distribution/v3/registry/storage/driver/inmemory" "github.com/distribution/distribution/v3/registry/storage/driver/inmemory"
"github.com/distribution/distribution/v3/testutil" "github.com/distribution/distribution/v3/testutil"
"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

@ -18,7 +18,6 @@ import (
"github.com/distribution/distribution/v3" "github.com/distribution/distribution/v3"
"github.com/distribution/distribution/v3/context" "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/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/reference"
"github.com/distribution/distribution/v3/registry/api/errcode" "github.com/distribution/distribution/v3/registry/api/errcode"
@ -934,9 +933,7 @@ func newRandomSchemaV1Manifest(name reference.Named, tag string, blobCount int)
Architecture: "x86", Architecture: "x86",
FSLayers: blobs, FSLayers: blobs,
History: history, History: history,
Versioned: manifest.Versioned{ Versioned: schema1.SchemaVersion, //nolint:staticcheck // Ignore SA1019: "github.com/distribution/distribution/v3/manifest/schema1" is deprecated, as it's used for backward compatibility.
SchemaVersion: 1,
},
} }
pk, err := libtrust.GenerateECP256PrivateKey() pk, err := libtrust.GenerateECP256PrivateKey()

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/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/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/distribution/distribution/v3/manifest/schema2"
@ -35,6 +34,7 @@ import (
"github.com/docker/libtrust" "github.com/docker/libtrust"
"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{
@ -1532,9 +1532,7 @@ func testManifestAPISchema1(t *testing.T, env *testEnv, imageName reference.Name
// -------------------------------- // --------------------------------
// Attempt to push unsigned manifest with missing layers // 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. 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{ Versioned: schema1.SchemaVersion, //nolint:staticcheck // Ignore SA1019: "github.com/distribution/distribution/v3/manifest/schema1" is deprecated, as it's used for backward compatibility.
SchemaVersion: 1,
},
Name: imageName.Name(), Name: imageName.Name(),
Tag: tag, 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. FSLayers: []schema1.FSLayer{ //nolint:staticcheck // Ignore SA1019: "github.com/distribution/distribution/v3/manifest/schema1" is deprecated, as it's used for backward compatibility.
@ -1851,10 +1849,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,
@ -2174,10 +2170,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{
@ -2969,9 +2963,7 @@ 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. 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{ Versioned: schema1.SchemaVersion, //nolint:staticcheck // Ignore SA1019: "github.com/distribution/distribution/v3/manifest/schema1" is deprecated, as it's used for backward compatibility.
SchemaVersion: 1,
},
Name: imageName, Name: imageName,
Tag: tag, 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. FSLayers: []schema1.FSLayer{ //nolint:staticcheck // Ignore SA1019: "github.com/distribution/distribution/v3/manifest/schema1" is deprecated, as it's used for backward compatibility.
@ -3043,9 +3035,7 @@ func TestRegistryAsCacheMutationAPIs(t *testing.T) {
// Manifest upload // 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. 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{ Versioned: schema1.SchemaVersion, //nolint:staticcheck // Ignore SA1019: "github.com/distribution/distribution/v3/manifest/schema1" is deprecated, as it's used for backward compatibility.
SchemaVersion: 1,
},
Name: imageName.Name(), Name: imageName.Name(),
Tag: tag, 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. FSLayers: []schema1.FSLayer{}, //nolint:staticcheck // Ignore SA1019: "github.com/distribution/distribution/v3/manifest/schema1" is deprecated, as it's used for backward compatibility.

View file

@ -17,6 +17,7 @@ import (
"github.com/distribution/distribution/v3/registry/storage/driver/inmemory" "github.com/distribution/distribution/v3/registry/storage/driver/inmemory"
"github.com/distribution/distribution/v3/testutil" "github.com/distribution/distribution/v3/testutil"
"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

@ -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/ocischema" "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/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/reference"
@ -19,6 +18,7 @@ import (
"github.com/distribution/distribution/v3/testutil" "github.com/distribution/distribution/v3/testutil"
"github.com/docker/libtrust" "github.com/docker/libtrust"
"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"
) )
@ -80,9 +80,7 @@ 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. 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{ Versioned: specs.Versioned{SchemaVersion: 1},
SchemaVersion: 1,
},
Name: env.name.Name(), Name: env.name.Name(),
Tag: env.tag, Tag: env.tag,
} }
@ -495,7 +493,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,10 +49,8 @@ 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,
} }
@ -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/context" "github.com/distribution/distribution/v3/context"
"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) {
@ -43,10 +43,8 @@ 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,
} }
@ -172,10 +170,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/reference" "github.com/distribution/distribution/v3/reference"
"github.com/distribution/distribution/v3/registry/storage/driver/inmemory" "github.com/distribution/distribution/v3/registry/storage/driver/inmemory"
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,

View file

@ -5,12 +5,12 @@ import (
"github.com/distribution/distribution/v3" "github.com/distribution/distribution/v3"
"github.com/distribution/distribution/v3/context" "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/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/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/distribution/distribution/v3/manifest/schema2"
"github.com/docker/libtrust" "github.com/docker/libtrust"
"github.com/opencontainers/go-digest" "github.com/opencontainers/go-digest"
"github.com/opencontainers/image-spec/specs-go"
) )
// MakeManifestList constructs a manifest list out of a list of manifest digests // MakeManifestList constructs a manifest list out of a list of manifest digests
@ -46,9 +46,7 @@ func MakeManifestList(blobstatter distribution.BlobStatter, manifestDigests []di
// Use Docker Image Manifest v2, Schema 2, or the OCI Image Specification. // Use Docker Image Manifest v2, Schema 2, or the OCI Image Specification.
func MakeSchema1Manifest(digests []digest.Digest) (*schema1.SignedManifest, error) { func MakeSchema1Manifest(digests []digest.Digest) (*schema1.SignedManifest, error) {
mfst := schema1.Manifest{ mfst := schema1.Manifest{
Versioned: manifest.Versioned{ Versioned: specs.Versioned{SchemaVersion: 1},
SchemaVersion: 1,
},
Name: "who", Name: "who",
Tag: "cares", Tag: "cares",
} }