Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Signed-off-by: Aviral Takkar <aviral26@users.noreply.github.com>
  • Loading branch information
aviral26 committed Jun 17, 2021
1 parent 906a2ab commit 8d80ba7
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 44 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/docker/distribution

go 1.12

replace github.com/opencontainers/artifacts => github.com/aviral26/artifacts v0.0.0-20210401062346-2b83ac8c6d72
replace github.com/opencontainers/artifacts => github.com/aviral26/artifacts v0.0.3

require (
github.com/Azure/azure-sdk-for-go v16.2.1+incompatible
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ github.com/Shopify/logrus-bugsnag v0.0.0-20171204204709-577dee27f20d h1:UrqY+r/O
github.com/Shopify/logrus-bugsnag v0.0.0-20171204204709-577dee27f20d/go.mod h1:HI8ITrYtUY+O+ZhtlqUnD8+KwNPOyugEhfP9fdUIaEQ=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/aviral26/artifacts v0.0.0-20210401062346-2b83ac8c6d72 h1:wdeNiQZOLF3PTtEQ2xndkMV7kQC1qejSdZidszgWpaY=
github.com/aviral26/artifacts v0.0.0-20210401062346-2b83ac8c6d72/go.mod h1:IBQOjhxIKxb9G4h9NiWAJLGBgKPlIy27tcpPDTAfUQw=
github.com/aviral26/artifacts v0.0.3 h1:F+XBw93sXm9H7iajUEl0DhbbvCg2e/k6e4lVY2EYhC4=
github.com/aviral26/artifacts v0.0.3/go.mod h1:IBQOjhxIKxb9G4h9NiWAJLGBgKPlIy27tcpPDTAfUQw=
github.com/aws/aws-sdk-go v1.15.11 h1:m45+Ru/wA+73cOZXiEGLDH2d9uLN3iHqMc0/z4noDXE=
github.com/aws/aws-sdk-go v1.15.11/go.mod h1:mFuSZ37Z9YOHbQEwBWztmVzqXrEkub65tZoCYDt7FT0=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
Expand Down
28 changes: 7 additions & 21 deletions manifest/artifact/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
// ArtifactVersion provides a pre-initialized version structure for this
// packages Artifact version of the manifest.
var ArtifactVersion = manifest.Versioned{
SchemaVersion: 2,
SchemaVersion: 3,
MediaType: v2.MediaTypeArtifactManifest,
}

Expand Down Expand Up @@ -62,30 +62,16 @@ func (a Artifact) References() []distribution.Descriptor {
Size: a.inner.Blobs[i].Size,
}
}

if a.inner.Config != nil {
blobs = append(blobs, distribution.Descriptor{
MediaType: a.inner.Config.MediaType,
Digest: a.inner.Config.Digest,
Size: a.inner.Config.Size,
})
}

return blobs
}

// Manifests returns the distribution descriptors for the manifests that this artifact is linked to.
func (a Artifact) Manifests() []distribution.Descriptor {
dependsOn := make([]distribution.Descriptor, len(a.inner.Manifests))
for i := range a.inner.Manifests {
dependsOn[i] = distribution.Descriptor{
MediaType: a.inner.Manifests[i].MediaType,
Digest: a.inner.Manifests[i].Digest,
Size: a.inner.Manifests[i].Size,
}
// SubjectManifest returns the the subject manifest this artifact is linked to.
func (a Artifact) SubjectManifest() distribution.Descriptor {
return distribution.Descriptor{
MediaType: a.inner.SubjectManifest.MediaType,
Digest: a.inner.SubjectManifest.Digest,
Size: a.inner.SubjectManifest.Size,
}

return dependsOn
}

// DeserializedArtifact wraps Artifact with a copy of the original JSON.
Expand Down
4 changes: 2 additions & 2 deletions registry/api/v2/descriptors.go
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ var routeDescriptors = []RouteDescriptor{

{
Name: RouteNameManifestLinkedArtifacts,
Path: "/v2/_ext/oci-artifacts/v1/{name:" + reference.NameRegexp.String() + "}/manifests/{reference:" + reference.TagRegexp.String() + "|" + digest.DigestRegexp.String() + "}/references",
Path: "/v2/_ext/oci-artifacts/v1-rc1/{name:" + reference.NameRegexp.String() + "}/manifests/{reference:" + reference.TagRegexp.String() + "|" + digest.DigestRegexp.String() + "}/referrers",
Entity: "Linked artifacts",
Description: "Retrieve information about artifacts linked to this manifest.",
Methods: []MethodDescriptor{
Expand All @@ -728,7 +728,7 @@ var routeDescriptors = []RouteDescriptor{
},
QueryParameters: []ParameterDescriptor{
{
Name: "artifact-type",
Name: "referenceType",
Type: "query",
Format: "<artifactType>",
Description: `Artifact type of the requested linked artifacts.`,
Expand Down
2 changes: 1 addition & 1 deletion registry/handlers/referrers.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (mrmh *referrersHandler) Artifacts(w http.ResponseWriter, r *http.Request)
dcontext.GetLogger(mrmh).Debug("Artifacts")

// This can be empty
artifactType := r.FormValue("artifact-type")
artifactType := r.FormValue("referenceType")

if mrmh.Tag != "" {
tags := mrmh.Repository.Tags(mrmh)
Expand Down
7 changes: 5 additions & 2 deletions registry/storage/manifeststore.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ func (ms *manifestStore) Get(ctx context.Context, dgst digest.Digest, options ..
return ms.ocischemaHandler.Unmarshal(ctx, dgst, content)
case manifestlist.MediaTypeManifestList, v1.MediaTypeImageIndex:
return ms.manifestListHandler.Unmarshal(ctx, dgst, content)
case v2.MediaTypeArtifactManifest:
return ms.ociArtifactHandler.Unmarshal(ctx, dgst, content)
case "":
// OCI image or image index - no media type in the content

Expand All @@ -133,6 +131,11 @@ func (ms *manifestStore) Get(ctx context.Context, dgst digest.Digest, options ..
default:
return nil, distribution.ErrManifestVerification{fmt.Errorf("unrecognized manifest content type %s", versioned.MediaType)}
}
case 3:
switch versioned.MediaType {
case v2.MediaTypeArtifactManifest:
return ms.ociArtifactHandler.Unmarshal(ctx, dgst, content)
}
}

return nil, fmt.Errorf("unrecognized manifest schema version %d", versioned.SchemaVersion)
Expand Down
28 changes: 13 additions & 15 deletions registry/storage/ociartifacthandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,13 @@ func (ah *ociArtifactHandler) verifyManifest(ctx context.Context, da artifact.De
return err
}

// All manifests to link to must exist.
for _, manifestDesc := range da.Manifests() {
exists, err := manifestService.Exists(ctx, manifestDesc.Digest)
if err != nil {
errs = append(errs, err)
} else {
if !exists {
errs = append(errs, distribution.ErrManifestUnknownRevision{Revision: manifestDesc.Digest})
}
}
// Validate subject manifest.
subject := da.SubjectManifest()
exists, err := manifestService.Exists(ctx, subject.Digest)
if !exists || err == distribution.ErrBlobUnknown {
errs = append(errs, distribution.ErrManifestBlobUnknown{Digest: subject.Digest})
} else if err != nil {
errs = append(errs, err)
}
}

Expand All @@ -114,11 +111,12 @@ func (ah *ociArtifactHandler) verifyManifest(ctx context.Context, da artifact.De

func (ah *ociArtifactHandler) linkManifests(ctx context.Context, da artifact.DeserializedArtifact, revision digest.Digest) error {
daArtifactType := da.ArtifactType()
// Link the artifact as referrer metadata to each dependsOn manifest.
for _, manifestDesc := range da.Manifests() {
if err := ah.referrersStoreFunc(manifestDesc.Digest, daArtifactType).linkBlob(ctx, distribution.Descriptor{Digest: revision}); err != nil {
return err
}

// Index referrer metadata for the subject.
subject := da.SubjectManifest()
if err := ah.referrersStoreFunc(subject.Digest, daArtifactType).linkBlob(ctx, distribution.Descriptor{Digest: revision}); err != nil {
return err
}

return nil
}

0 comments on commit 8d80ba7

Please sign in to comment.