Skip to content

Commit

Permalink
Merge branch 'referrers' into feature_oras_referrers
Browse files Browse the repository at this point in the history
  • Loading branch information
aviral26 committed Sep 13, 2021
2 parents d95790d + 018d63a commit 1799186
Show file tree
Hide file tree
Showing 15 changed files with 127 additions and 158 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ cat <<EOF > $artifactFile
"size": $signatureFileSize
}
],
"subjectManifest": {
"subject": {
"mediaType": "$manifestMediaType",
"digest": "$manifestDigest",
"size": $manifestFileSize
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ require (
github.com/ncw/swift v1.0.47
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.0.1
github.com/oras-project/artifacts-spec v0.0.0-20210826181006-68f2cefa34a6
github.com/oras-project/artifacts-spec v0.0.0-20210910233110-813953a626ae
github.com/satori/go.uuid v1.2.0 // indirect
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v0.0.3
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,8 @@ github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.0.1 h1:JMemWkRwHx4Zj+fVxWoMCFm/8sYGGrUVojFA6h/TRcI=
github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
github.com/oras-project/artifacts-spec v0.0.0-20210820222200-769b88c06428 h1:amnau8Czf7c+KCq14179DmXq9tLt0b/tGg+xusz2L2Q=
github.com/oras-project/artifacts-spec v0.0.0-20210820222200-769b88c06428/go.mod h1:Xch2aLzSwtkhbFFN6LUzTfLtukYvMMdXJ4oZ8O7BOdc=
github.com/oras-project/artifacts-spec v0.0.0-20210826181006-68f2cefa34a6 h1:BZYj7fsb3kZb2INlysMzTeLZ1ksxwwn4BreryzyI2KM=
github.com/oras-project/artifacts-spec v0.0.0-20210826181006-68f2cefa34a6/go.mod h1:Xch2aLzSwtkhbFFN6LUzTfLtukYvMMdXJ4oZ8O7BOdc=
github.com/oras-project/artifacts-spec v0.0.0-20210910233110-813953a626ae h1:vw1ccIckPxFFx3/wW8SaVLtvQ5viAduN+fuku8KbEfo=
github.com/oras-project/artifacts-spec v0.0.0-20210910233110-813953a626ae/go.mod h1:Xch2aLzSwtkhbFFN6LUzTfLtukYvMMdXJ4oZ8O7BOdc=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
30 changes: 10 additions & 20 deletions manifest/orasartifact/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ func init() {
return nil, distribution.Descriptor{}, err
}

if d.inner.MediaType != v1.MediaTypeArtifactManifest {
err = fmt.Errorf("if present, mediaType in ORAS artifact manifest should be '%s' not '%s'",
v1.MediaTypeArtifactManifest, d.inner.MediaType)

return nil, distribution.Descriptor{}, err
}

dgst := digest.FromBytes(b)
return d, distribution.Descriptor{Digest: dgst, Size: int64(len(b)), MediaType: v1.MediaTypeArtifactManifest}, err
}
Expand Down Expand Up @@ -57,12 +50,12 @@ func (a Manifest) References() []distribution.Descriptor {
return blobs
}

// SubjectManifest returns the the subject manifest this artifact references.
func (a Manifest) SubjectManifest() distribution.Descriptor {
// Subject returns the the subject manifest this artifact references.
func (a Manifest) Subject() distribution.Descriptor {
return distribution.Descriptor{
MediaType: a.inner.SubjectManifest.MediaType,
Digest: a.inner.SubjectManifest.Digest,
Size: a.inner.SubjectManifest.Size,
MediaType: a.inner.Subject.MediaType,
Digest: a.inner.Subject.Digest,
Size: a.inner.Subject.Size,
}
}

Expand All @@ -83,6 +76,9 @@ func (d *DeserializedManifest) UnmarshalJSON(b []byte) error {
if err := json.Unmarshal(d.raw, &man); err != nil {
return err
}
if man.ArtifactType == "" {
return errors.New("artifactType cannot be empty")
}
d.inner = man

return nil
Expand All @@ -100,12 +96,6 @@ func (d *DeserializedManifest) MarshalJSON() ([]byte, error) {
// Payload returns the raw content of the Artifact. The contents can be
// used to calculate the content identifier.
func (d DeserializedManifest) Payload() (string, []byte, error) {
var mediaType string
if d.inner.MediaType == "" {
mediaType = v1.MediaTypeArtifactManifest
} else {
mediaType = d.inner.MediaType
}

return mediaType, d.raw, nil
// NOTE: This is a hack. The media type should be read from storage.
return v1.MediaTypeArtifactManifest, d.raw, nil
}
20 changes: 2 additions & 18 deletions manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"mime"

"github.com/opencontainers/go-digest"
orasartifact "github.com/oras-project/artifacts-spec/specs-go/v1"
)

// Manifest represents a registry object specifying a set of
Expand Down Expand Up @@ -47,23 +48,6 @@ type ManifestBuilder interface {
AppendReference(dependency Describable) error
}

// ArtifactDescriptor describes targeted reference type content.
type ArtifactDescriptor struct {
// MediaType describe the type of the content. All text based formats are
// encoded as utf-8.
MediaType string `json:"mediaType,omitempty"`

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

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

// ArtifactType specifies the artifact type of the content.
ArtifactType string `json:"artifactType,omitempty"`
}

// ManifestService describes operations on image manifests.
type ManifestService interface {
// Exists returns true if the manifest exists.
Expand All @@ -81,7 +65,7 @@ type ManifestService interface {

// Referrers returns a collection of manifests which reference the given manifest,
// filtered by artifactType.
Referrers(ctx context.Context, dgst digest.Digest, artifactType string) ([]ArtifactDescriptor, error)
Referrers(ctx context.Context, dgst digest.Digest, artifactType string) ([]orasartifact.Descriptor, error)
}

// ManifestEnumerator enables iterating over manifests
Expand Down
3 changes: 2 additions & 1 deletion registry/client/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/distribution/distribution/v3/registry/storage/cache"
"github.com/distribution/distribution/v3/registry/storage/cache/memory"
"github.com/opencontainers/go-digest"
orasartifacts "github.com/oras-project/artifacts-spec/specs-go/v1"
)

// Registry provides an interface for calling Repositories, which returns a catalog of repositories.
Expand Down Expand Up @@ -397,7 +398,7 @@ type manifests struct {
etags map[string]string
}

func (ms *manifests) Referrers(_ context.Context, _ digest.Digest, _ string) ([]distribution.ArtifactDescriptor, error) {
func (ms *manifests) Referrers(_ context.Context, _ digest.Digest, _ string) ([]orasartifacts.Descriptor, error) {
return nil, fmt.Errorf("not implemented")
}

Expand Down
7 changes: 4 additions & 3 deletions registry/handlers/referrers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import (
"net/http"

"github.com/distribution/distribution/v3"
dcontext "github.com/distribution/distribution/v3/context"
"github.com/distribution/distribution/v3/registry/api/errcode"
v2 "github.com/distribution/distribution/v3/registry/api/v2"
dcontext "github.com/distribution/distribution/v3/context"
"github.com/gorilla/handlers"
"github.com/opencontainers/go-digest"
orasartifacts "github.com/oras-project/artifacts-spec/specs-go/v1"
)

// referrersDispatcher takes the request context and builds the
Expand All @@ -29,7 +30,7 @@ func referrersDispatcher(ctx *Context, r *http.Request) http.Handler {

// referrersResponse describes the response body of the referrers API.
type referrersResponse struct {
Referrers []distribution.ArtifactDescriptor `json:"references"`
Referrers []orasartifacts.Descriptor `json:"references"`
}

// referrersHandler handles http operations on manifest referrers.
Expand Down Expand Up @@ -70,7 +71,7 @@ func (h *referrersHandler) Get(w http.ResponseWriter, r *http.Request) {
}

if referrers == nil {
referrers = []distribution.ArtifactDescriptor{}
referrers = []orasartifacts.Descriptor{}
}

response := referrersResponse{}
Expand Down
3 changes: 2 additions & 1 deletion registry/proxy/proxymanifeststore.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/distribution/distribution/v3/reference"
"github.com/distribution/distribution/v3/registry/proxy/scheduler"
"github.com/opencontainers/go-digest"
orasartifacts "github.com/oras-project/artifacts-spec/specs-go/v1"
)

// todo(richardscothern): from cache control header or config
Expand All @@ -25,7 +26,7 @@ type proxyManifestStore struct {

var _ distribution.ManifestService = &proxyManifestStore{}

func (pms proxyManifestStore) Referrers(_ context.Context, _ digest.Digest, _ string) ([]distribution.ArtifactDescriptor, error) {
func (pms proxyManifestStore) Referrers(_ context.Context, _ digest.Digest, _ string) ([]orasartifacts.Descriptor, error) {
return nil, distribution.ErrUnsupported
}

Expand Down
3 changes: 2 additions & 1 deletion registry/proxy/proxymanifeststore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/distribution/distribution/v3/testutil"
"github.com/docker/libtrust"
"github.com/opencontainers/go-digest"
orasartifacts "github.com/oras-project/artifacts-spec/specs-go/v1"
)

type statsManifest struct {
Expand Down Expand Up @@ -61,7 +62,7 @@ func (sm statsManifest) Put(ctx context.Context, manifest distribution.Manifest,
return sm.manifests.Put(ctx, manifest)
}

func (sm statsManifest) Referrers(ctx context.Context, dgst digest.Digest, referrerType string) ([]distribution.ArtifactDescriptor, error) {
func (sm statsManifest) Referrers(ctx context.Context, dgst digest.Digest, referrerType string) ([]orasartifacts.Descriptor, error) {
sm.stats["referrers"]++
return sm.Referrers(ctx, dgst, referrerType)
}
Expand Down
16 changes: 6 additions & 10 deletions registry/storage/manifeststore.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,9 @@ func (ms *manifestStore) Get(ctx context.Context, dgst digest.Digest, options ..
return nil, distribution.ErrManifestVerification{fmt.Errorf("unrecognized manifest content type %s", versioned.MediaType)}
}
default:
switch versioned.MediaType {
case orasartifactv1.MediaTypeArtifactManifest:
return ms.orasArtifactHandler.Unmarshal(ctx, dgst, content)
}
// Assume it's an ORAS artifact manifest.
return ms.orasArtifactHandler.Unmarshal(ctx, dgst, content)
}

return nil, fmt.Errorf("unrecognized manifest schema version %d", versioned.SchemaVersion)
}

func (ms *manifestStore) Put(ctx context.Context, manifest distribution.Manifest, options ...distribution.ManifestServiceOption) (digest.Digest, error) {
Expand All @@ -162,10 +158,10 @@ func (ms *manifestStore) Put(ctx context.Context, manifest distribution.Manifest
}

// Referrers returns referrer manifests filtered by the given referrerType.
func (ms *manifestStore) Referrers(ctx context.Context, revision digest.Digest, referrerType string) ([]distribution.ArtifactDescriptor, error) {
func (ms *manifestStore) Referrers(ctx context.Context, revision digest.Digest, referrerType string) ([]orasartifactv1.Descriptor, error) {
dcontext.GetLogger(ms.ctx).Debug("(*manifestStore).Referrers")

var referrers []distribution.ArtifactDescriptor
var referrers []orasartifactv1.Descriptor

err := ms.referrersStore(ctx, revision, referrerType).Enumerate(ctx, func(referrerRevision digest.Digest) error {
man, err := ms.Get(ctx, referrerRevision)
Expand All @@ -184,10 +180,10 @@ func (ms *manifestStore) Referrers(ctx context.Context, revision digest.Digest,
return err
}
desc.MediaType, _, _ = man.Payload()
referrers = append(referrers, distribution.ArtifactDescriptor{
referrers = append(referrers, orasartifactv1.Descriptor{
MediaType: desc.MediaType,
Size: desc.Size,
Digest: desc.Digest.String(),
Digest: desc.Digest,
ArtifactType: orasArtifactMan.ArtifactType(),
})
return nil
Expand Down
4 changes: 2 additions & 2 deletions registry/storage/orasartifactmanifesthandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (oamh *orasArtifactManifestHandler) verifyManifest(ctx context.Context, dm
}

// Validate subject manifest.
subject := dm.SubjectManifest()
subject := dm.Subject()
exists, err := ms.Exists(ctx, subject.Digest)
if !exists || err == distribution.ErrBlobUnknown {
errs = append(errs, distribution.ErrManifestBlobUnknown{Digest: subject.Digest})
Expand All @@ -113,7 +113,7 @@ func (oamh *orasArtifactManifestHandler) verifyManifest(ctx context.Context, dm
// indexReferrers indexes the subject of the given revision in its referrers index store.
func (oamh *orasArtifactManifestHandler) indexReferrers(ctx context.Context, dm orasartifact.DeserializedManifest, revision digest.Digest) error {
artifactType := dm.ArtifactType()
subject := dm.SubjectManifest()
subject := dm.Subject()

if err := oamh.referrersStore(ctx, subject.Digest, artifactType).linkBlob(ctx, distribution.Descriptor{Digest: revision}); err != nil {
return err
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1799186

Please sign in to comment.