Skip to content

Commit 1799186

Browse files
committed
Merge branch 'referrers' into feature_oras_referrers
2 parents d95790d + 018d63a commit 1799186

File tree

15 files changed

+127
-158
lines changed

15 files changed

+127
-158
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ cat <<EOF > $artifactFile
104104
"size": $signatureFileSize
105105
}
106106
],
107-
"subjectManifest": {
107+
"subject": {
108108
"mediaType": "$manifestMediaType",
109109
"digest": "$manifestDigest",
110110
"size": $manifestFileSize

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ require (
3232
github.com/ncw/swift v1.0.47
3333
github.com/opencontainers/go-digest v1.0.0
3434
github.com/opencontainers/image-spec v1.0.1
35-
github.com/oras-project/artifacts-spec v0.0.0-20210826181006-68f2cefa34a6
35+
github.com/oras-project/artifacts-spec v0.0.0-20210910233110-813953a626ae
3636
github.com/satori/go.uuid v1.2.0 // indirect
3737
github.com/sirupsen/logrus v1.8.1
3838
github.com/spf13/cobra v0.0.3

go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,8 @@ github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8
9696
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
9797
github.com/opencontainers/image-spec v1.0.1 h1:JMemWkRwHx4Zj+fVxWoMCFm/8sYGGrUVojFA6h/TRcI=
9898
github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
99-
github.com/oras-project/artifacts-spec v0.0.0-20210820222200-769b88c06428 h1:amnau8Czf7c+KCq14179DmXq9tLt0b/tGg+xusz2L2Q=
100-
github.com/oras-project/artifacts-spec v0.0.0-20210820222200-769b88c06428/go.mod h1:Xch2aLzSwtkhbFFN6LUzTfLtukYvMMdXJ4oZ8O7BOdc=
101-
github.com/oras-project/artifacts-spec v0.0.0-20210826181006-68f2cefa34a6 h1:BZYj7fsb3kZb2INlysMzTeLZ1ksxwwn4BreryzyI2KM=
102-
github.com/oras-project/artifacts-spec v0.0.0-20210826181006-68f2cefa34a6/go.mod h1:Xch2aLzSwtkhbFFN6LUzTfLtukYvMMdXJ4oZ8O7BOdc=
99+
github.com/oras-project/artifacts-spec v0.0.0-20210910233110-813953a626ae h1:vw1ccIckPxFFx3/wW8SaVLtvQ5viAduN+fuku8KbEfo=
100+
github.com/oras-project/artifacts-spec v0.0.0-20210910233110-813953a626ae/go.mod h1:Xch2aLzSwtkhbFFN6LUzTfLtukYvMMdXJ4oZ8O7BOdc=
103101
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
104102
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
105103
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

manifest/orasartifact/manifest.go

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@ func init() {
1818
return nil, distribution.Descriptor{}, err
1919
}
2020

21-
if d.inner.MediaType != v1.MediaTypeArtifactManifest {
22-
err = fmt.Errorf("if present, mediaType in ORAS artifact manifest should be '%s' not '%s'",
23-
v1.MediaTypeArtifactManifest, d.inner.MediaType)
24-
25-
return nil, distribution.Descriptor{}, err
26-
}
27-
2821
dgst := digest.FromBytes(b)
2922
return d, distribution.Descriptor{Digest: dgst, Size: int64(len(b)), MediaType: v1.MediaTypeArtifactManifest}, err
3023
}
@@ -57,12 +50,12 @@ func (a Manifest) References() []distribution.Descriptor {
5750
return blobs
5851
}
5952

60-
// SubjectManifest returns the the subject manifest this artifact references.
61-
func (a Manifest) SubjectManifest() distribution.Descriptor {
53+
// Subject returns the the subject manifest this artifact references.
54+
func (a Manifest) Subject() distribution.Descriptor {
6255
return distribution.Descriptor{
63-
MediaType: a.inner.SubjectManifest.MediaType,
64-
Digest: a.inner.SubjectManifest.Digest,
65-
Size: a.inner.SubjectManifest.Size,
56+
MediaType: a.inner.Subject.MediaType,
57+
Digest: a.inner.Subject.Digest,
58+
Size: a.inner.Subject.Size,
6659
}
6760
}
6861

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

8884
return nil
@@ -100,12 +96,6 @@ func (d *DeserializedManifest) MarshalJSON() ([]byte, error) {
10096
// Payload returns the raw content of the Artifact. The contents can be
10197
// used to calculate the content identifier.
10298
func (d DeserializedManifest) Payload() (string, []byte, error) {
103-
var mediaType string
104-
if d.inner.MediaType == "" {
105-
mediaType = v1.MediaTypeArtifactManifest
106-
} else {
107-
mediaType = d.inner.MediaType
108-
}
109-
110-
return mediaType, d.raw, nil
99+
// NOTE: This is a hack. The media type should be read from storage.
100+
return v1.MediaTypeArtifactManifest, d.raw, nil
111101
}

manifests.go

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"mime"
77

88
"github.com/opencontainers/go-digest"
9+
orasartifact "github.com/oras-project/artifacts-spec/specs-go/v1"
910
)
1011

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

50-
// ArtifactDescriptor describes targeted reference type content.
51-
type ArtifactDescriptor struct {
52-
// MediaType describe the type of the content. All text based formats are
53-
// encoded as utf-8.
54-
MediaType string `json:"mediaType,omitempty"`
55-
56-
// Size in bytes of content.
57-
Size int64 `json:"size,omitempty"`
58-
59-
// Digest uniquely identifies the content. A byte stream can be verified
60-
// against this digest.
61-
Digest string `json:"digest,omitempty"`
62-
63-
// ArtifactType specifies the artifact type of the content.
64-
ArtifactType string `json:"artifactType,omitempty"`
65-
}
66-
6751
// ManifestService describes operations on image manifests.
6852
type ManifestService interface {
6953
// Exists returns true if the manifest exists.
@@ -81,7 +65,7 @@ type ManifestService interface {
8165

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

8771
// ManifestEnumerator enables iterating over manifests

registry/client/repository.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/distribution/distribution/v3/registry/storage/cache"
2222
"github.com/distribution/distribution/v3/registry/storage/cache/memory"
2323
"github.com/opencontainers/go-digest"
24+
orasartifacts "github.com/oras-project/artifacts-spec/specs-go/v1"
2425
)
2526

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

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

registry/handlers/referrers.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import (
55
"net/http"
66

77
"github.com/distribution/distribution/v3"
8+
dcontext "github.com/distribution/distribution/v3/context"
89
"github.com/distribution/distribution/v3/registry/api/errcode"
910
v2 "github.com/distribution/distribution/v3/registry/api/v2"
10-
dcontext "github.com/distribution/distribution/v3/context"
1111
"github.com/gorilla/handlers"
1212
"github.com/opencontainers/go-digest"
13+
orasartifacts "github.com/oras-project/artifacts-spec/specs-go/v1"
1314
)
1415

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

3031
// referrersResponse describes the response body of the referrers API.
3132
type referrersResponse struct {
32-
Referrers []distribution.ArtifactDescriptor `json:"references"`
33+
Referrers []orasartifacts.Descriptor `json:"references"`
3334
}
3435

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

7273
if referrers == nil {
73-
referrers = []distribution.ArtifactDescriptor{}
74+
referrers = []orasartifacts.Descriptor{}
7475
}
7576

7677
response := referrersResponse{}

registry/proxy/proxymanifeststore.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/distribution/distribution/v3/reference"
1010
"github.com/distribution/distribution/v3/registry/proxy/scheduler"
1111
"github.com/opencontainers/go-digest"
12+
orasartifacts "github.com/oras-project/artifacts-spec/specs-go/v1"
1213
)
1314

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

2627
var _ distribution.ManifestService = &proxyManifestStore{}
2728

28-
func (pms proxyManifestStore) Referrers(_ context.Context, _ digest.Digest, _ string) ([]distribution.ArtifactDescriptor, error) {
29+
func (pms proxyManifestStore) Referrers(_ context.Context, _ digest.Digest, _ string) ([]orasartifacts.Descriptor, error) {
2930
return nil, distribution.ErrUnsupported
3031
}
3132

registry/proxy/proxymanifeststore_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/distribution/distribution/v3/testutil"
2020
"github.com/docker/libtrust"
2121
"github.com/opencontainers/go-digest"
22+
orasartifacts "github.com/oras-project/artifacts-spec/specs-go/v1"
2223
)
2324

2425
type statsManifest struct {
@@ -61,7 +62,7 @@ func (sm statsManifest) Put(ctx context.Context, manifest distribution.Manifest,
6162
return sm.manifests.Put(ctx, manifest)
6263
}
6364

64-
func (sm statsManifest) Referrers(ctx context.Context, dgst digest.Digest, referrerType string) ([]distribution.ArtifactDescriptor, error) {
65+
func (sm statsManifest) Referrers(ctx context.Context, dgst digest.Digest, referrerType string) ([]orasartifacts.Descriptor, error) {
6566
sm.stats["referrers"]++
6667
return sm.Referrers(ctx, dgst, referrerType)
6768
}

registry/storage/manifeststore.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,9 @@ func (ms *manifestStore) Get(ctx context.Context, dgst digest.Digest, options ..
133133
return nil, distribution.ErrManifestVerification{fmt.Errorf("unrecognized manifest content type %s", versioned.MediaType)}
134134
}
135135
default:
136-
switch versioned.MediaType {
137-
case orasartifactv1.MediaTypeArtifactManifest:
138-
return ms.orasArtifactHandler.Unmarshal(ctx, dgst, content)
139-
}
136+
// Assume it's an ORAS artifact manifest.
137+
return ms.orasArtifactHandler.Unmarshal(ctx, dgst, content)
140138
}
141-
142-
return nil, fmt.Errorf("unrecognized manifest schema version %d", versioned.SchemaVersion)
143139
}
144140

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

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

168-
var referrers []distribution.ArtifactDescriptor
164+
var referrers []orasartifactv1.Descriptor
169165

170166
err := ms.referrersStore(ctx, revision, referrerType).Enumerate(ctx, func(referrerRevision digest.Digest) error {
171167
man, err := ms.Get(ctx, referrerRevision)
@@ -184,10 +180,10 @@ func (ms *manifestStore) Referrers(ctx context.Context, revision digest.Digest,
184180
return err
185181
}
186182
desc.MediaType, _, _ = man.Payload()
187-
referrers = append(referrers, distribution.ArtifactDescriptor{
183+
referrers = append(referrers, orasartifactv1.Descriptor{
188184
MediaType: desc.MediaType,
189185
Size: desc.Size,
190-
Digest: desc.Digest.String(),
186+
Digest: desc.Digest,
191187
ArtifactType: orasArtifactMan.ArtifactType(),
192188
})
193189
return nil

0 commit comments

Comments
 (0)