forked from distribution/distribution
-
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c356da2
feat: index referrers for image manifest
wangxiaoxuan273 4e7b613
removed subject from references function
wangxiaoxuan273 2ac3b2d
addressed the comments
wangxiaoxuan273 ef45d9b
added 2 manifest media types
wangxiaoxuan273 1c15e35
removed schema1 manifest
wangxiaoxuan273 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,16 +8,18 @@ import ( | |
"github.com/distribution/distribution/v3" | ||
dcontext "github.com/distribution/distribution/v3/context" | ||
"github.com/distribution/distribution/v3/manifest/ocischema" | ||
"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 +58,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 | ||
} | ||
|
||
|
@@ -78,6 +86,21 @@ func (ms *ocischemaManifestHandler) verifyManifest(ctx context.Context, mnfst oc | |
return err | ||
} | ||
|
||
// validate the subject | ||
if mnfst.Subject != nil { | ||
// check if the digest is valid | ||
err := mnfst.Subject.Digest.Validate() | ||
if err != nil { | ||
errs = append(errs, err, distribution.ErrManifestBlobUnknown{Digest: mnfst.Subject.Digest}) | ||
} else { | ||
// check the presence | ||
exists, err := manifestService.Exists(ctx, mnfst.Subject.Digest) | ||
if err != nil || !exists { | ||
errs = append(errs, distribution.ErrManifestBlobUnknown{Digest: mnfst.Subject.Digest}) | ||
} | ||
} | ||
} | ||
|
||
blobsService := ms.repository.Blobs(ctx) | ||
|
||
for _, descriptor := range mnfst.References() { | ||
|
@@ -141,3 +164,20 @@ 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 | ||
|
||
referrersLinkPath, err := pathFor(referrersLinkPathSpec{name: ms.repository.Named().Name(), revision: revision, subjectRevision: subjectRevision}) | ||
if err != nil { | ||
return fmt.Errorf("failed to generate referrers link path for %v", revision) | ||
} | ||
return ms.storageDriver.PutContent(ctx, referrersLinkPath, []byte(revision.String())) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.