Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Descriptor an alias for oci.Descriptor #3888

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 4 additions & 36 deletions blobs.go
Expand Up @@ -46,7 +46,7 @@ func (err ErrBlobInvalidDigest) Error() string {
// instead of initiating an upload session.
type ErrBlobMounted struct {
From reference.Canonical
Descriptor Descriptor
Descriptor v1.Descriptor
}

func (err ErrBlobMounted) Error() string {
Expand All @@ -58,41 +58,9 @@ func (err ErrBlobMounted) Error() string {
// store, a descriptor can be used to fetch, store and target any kind of
// blob. The struct also describes the wire protocol format. Fields should
// only be added but never changed.
type Descriptor struct {
// MediaType describe the type of the content. All text based formats are
// encoded as utf-8.
MediaType string `json:"mediaType,omitempty"`

// Digest uniquely identifies the content. A byte stream can be verified
// against this digest.
Digest digest.Digest `json:"digest,omitempty"`

// Size in bytes of content.
Size int64 `json:"size,omitempty"`

// URLs contains the source URLs of this content.
URLs []string `json:"urls,omitempty"`

// Annotations contains arbitrary metadata relating to the targeted content.
Annotations map[string]string `json:"annotations,omitempty"`

// Platform describes the platform which the image in the manifest runs on.
// This should only be used when referring to a manifest.
Platform *v1.Platform `json:"platform,omitempty"`

// NOTE: Before adding a field here, please ensure that all
// other options have been exhausted. Much of the type relationships
// depend on the simplicity of this type.
}

// Descriptor returns the descriptor, to make it satisfy the Describable
// interface. Note that implementations of Describable are generally objects
// which can be described, not simply descriptors; this exception is in place
// to make it more convenient to pass actual descriptors to functions that
// expect Describable objects.
func (d Descriptor) Descriptor() Descriptor {
return d
}
//
// Descriptor is an alias for [v1.Descriptor].
type Descriptor = v1.Descriptor

// BlobStatter makes blob descriptors available by digest. The service may
// provide a descriptor of a different digest if the provided digest is not
Expand Down
20 changes: 14 additions & 6 deletions manifest/manifestlist/manifestlist.go
Expand Up @@ -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"
)

Expand All @@ -18,13 +19,19 @@ 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,
}

// OCISchemaVersion provides a pre-initialized version structure for this
// packages OCIschema version of the manifest.
//
// Deprecated: use [specs.Versioned] and set MediaType on the manifest
// to [v1.MediaTypeImageIndex].
var OCISchemaVersion = manifest.Versioned{
SchemaVersion: 2,
MediaType: v1.MediaTypeImageIndex,
Expand Down Expand Up @@ -117,7 +124,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"`
Expand Down Expand Up @@ -167,10 +177,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: 2,
MediaType: mediaType,
},
Versioned: specs.Versioned{SchemaVersion: 2},
MediaType: mediaType,
}

m.Manifests = make([]ManifestDescriptor, len(descriptors))
Expand Down Expand Up @@ -214,7 +222,7 @@ 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) {
func (m *DeserializedManifestList) Payload() (string, []byte, error) {
var mediaType string
if m.MediaType == "" {
mediaType = v1.MediaTypeImageIndex
Expand Down
24 changes: 17 additions & 7 deletions manifest/ocischema/builder.go
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -96,8 +94,20 @@ func (mb *Builder) Build(ctx context.Context) (distribution.Manifest, error) {
}

// AppendReference adds a reference to the current ManifestBuilder.
func (mb *Builder) AppendReference(d distribution.Describable) error {
mb.layers = append(mb.layers, d.Descriptor())
//
// The reference must be either a [distribution.Descriptor] or a
// [distribution.Describable].
func (mb *Builder) AppendReference(reference any) error {
var descriptor distribution.Descriptor
if dt, ok := reference.(distribution.Descriptor); ok {
descriptor = dt
} else if dt, ok := reference.(distribution.Describable); ok {
descriptor = dt.Descriptor()
} else {
return errors.New("invalid type for reference: should be either a Descriptor or a Describable")
}

mb.layers = append(mb.layers, descriptor)
return nil
}

Expand Down
11 changes: 9 additions & 2 deletions manifest/ocischema/manifest.go
Expand Up @@ -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 this
// packages version of the manifest.
//
// Deprecated: use [specs.Versioned] and set MediaType on the manifest
// to [v1.MediaTypeImageManifest].
var SchemaVersion = manifest.Versioned{
SchemaVersion: 2, // historical value here.. does not pertain to OCI or docker version
MediaType: v1.MediaTypeImageManifest,
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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
}

Expand Down
8 changes: 3 additions & 5 deletions manifest/ocischema/manifest_test.go
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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",
Expand Down
20 changes: 14 additions & 6 deletions manifest/schema1/config_builder.go
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -247,10 +245,20 @@ func (mb *configManifestBuilder) emptyTar(ctx context.Context) (digest.Digest, e

// AppendReference adds a reference to the current ManifestBuilder.
//
// The reference must be either a [distribution.Descriptor] or a
// [distribution.Describable].
//
// Deprecated: Docker Image Manifest v2, Schema 1 is deprecated since 2015.
// Use Docker Image Manifest v2, Schema 2, or the OCI Image Specification.
func (mb *configManifestBuilder) AppendReference(d distribution.Describable) error {
descriptor := d.Descriptor()
func (mb *configManifestBuilder) AppendReference(reference any) error {
var descriptor distribution.Descriptor
if dt, ok := reference.(distribution.Descriptor); ok {
descriptor = dt
} else if dt, ok := reference.(distribution.Describable); ok {
descriptor = dt.Descriptor()
} else {
return errors.New("invalid type for reference: should be either a Descriptor or a Describable")
}

if err := descriptor.Digest.Validate(); err != nil {
return err
Expand Down
8 changes: 3 additions & 5 deletions manifest/schema1/manifest.go
Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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"`
Expand Down
12 changes: 6 additions & 6 deletions manifest/schema1/reference_builder.go
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -59,10 +57,12 @@ func (mb *referenceManifestBuilder) Build(ctx context.Context) (distribution.Man

// AppendReference adds a reference to the current ManifestBuilder.
//
// The reference must be a [Reference].
//
// Deprecated: Docker Image Manifest v2, Schema 1 is deprecated since 2015.
// Use Docker Image Manifest v2, Schema 2, or the OCI Image Specification.
func (mb *referenceManifestBuilder) AppendReference(d distribution.Describable) error {
r, ok := d.(Reference)
func (mb *referenceManifestBuilder) AppendReference(reference any) error {
r, ok := reference.(Reference)
if !ok {
return fmt.Errorf("unable to add non-reference type to v1 builder")
}
Expand Down
6 changes: 2 additions & 4 deletions manifest/schema1/reference_builder_test.go
Expand Up @@ -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",
Expand Down