-
Notifications
You must be signed in to change notification settings - Fork 5
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
feat: index referrers for image manifests #41
Changes from 4 commits
c356da2
4e7b613
2ac3b2d
ef45d9b
1c15e35
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,17 +7,22 @@ import ( | |
|
||
"github.com/distribution/distribution/v3" | ||
dcontext "github.com/distribution/distribution/v3/context" | ||
"github.com/distribution/distribution/v3/manifest/manifestlist" | ||
"github.com/distribution/distribution/v3/manifest/ocischema" | ||
"github.com/distribution/distribution/v3/manifest/schema1" | ||
"github.com/distribution/distribution/v3/manifest/schema2" | ||
"github.com/distribution/distribution/v3/registry/storage/driver" | ||
"github.com/opencontainers/go-digest" | ||
v1 "github.com/opencontainers/image-spec/specs-go/v1" | ||
) | ||
|
||
//ocischemaManifestHandler is a ManifestHandler that covers ocischema manifests. | ||
// ocischemaManifestHandler is a ManifestHandler that covers ocischema manifests. | ||
type ocischemaManifestHandler struct { | ||
repository distribution.Repository | ||
blobStore distribution.BlobStore | ||
ctx context.Context | ||
manifestURLs manifestURLs | ||
repository distribution.Repository | ||
blobStore distribution.BlobStore | ||
ctx context.Context | ||
manifestURLs manifestURLs | ||
storageDriver driver.StorageDriver | ||
} | ||
|
||
var _ ManifestHandler = &ocischemaManifestHandler{} | ||
|
@@ -56,6 +61,12 @@ func (ms *ocischemaManifestHandler) Put(ctx context.Context, manifest distributi | |
return "", err | ||
} | ||
|
||
err = ms.indexReferrers(ctx, m, revision.Digest) | ||
if err != nil { | ||
dcontext.GetLogger(ctx).Errorf("error indexing referrers: %v", err) | ||
return "", err | ||
} | ||
|
||
return revision.Digest, nil | ||
} | ||
|
||
|
@@ -109,7 +120,7 @@ func (ms *ocischemaManifestHandler) verifyManifest(ctx context.Context, mnfst oc | |
} | ||
} | ||
|
||
case v1.MediaTypeImageManifest: | ||
case v1.MediaTypeImageManifest, v1.MediaTypeArtifactManifest, v1.MediaTypeImageIndex, schema1.MediaTypeManifest, schema2.MediaTypeManifest, manifestlist.MediaTypeManifestList: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed. |
||
var exists bool | ||
exists, err = manifestService.Exists(ctx, descriptor.Digest) | ||
if err != nil || !exists { | ||
|
@@ -141,3 +152,16 @@ func (ms *ocischemaManifestHandler) verifyManifest(ctx context.Context, mnfst oc | |
|
||
return nil | ||
} | ||
|
||
// indexReferrers indexes the subject of the given revision in its referrers index store. | ||
func (ms *ocischemaManifestHandler) indexReferrers(ctx context.Context, dm *ocischema.DeserializedManifest, revision digest.Digest) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is probably OK since |
||
if dm.Subject == nil { | ||
return nil | ||
} | ||
|
||
// [TODO] We can use artifact type in the link path to support filtering by artifact type | ||
// but need to consider the max path length in different os | ||
subjectRevision := dm.Subject.Digest | ||
|
||
return indexWithSubject(ctx, ms.repository.Named().Name(), revision, subjectRevision, ms.storageDriver) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to also update the
Reference()
function?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
subject
inReference()
and changed theverifyManifest
function accordingly.