Skip to content
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: support artifact discovering in OCI image layout #765

Merged
merged 20 commits into from
Jan 29, 2023

Conversation

qweeah
Copy link
Contributor

@qweeah qweeah commented Jan 28, 2023

This PR adds OCI image layout support for oras discover command and resolves #760. The UX is consistent with remote registry and looks like below:

# 0. Copy the test DAG to local OCI image layout folder
$ oras cp jinzha1.azurecr.io/oci-root:foo -r --to-oci-layout oci-root:foo

# 1. Discovering referrers
$ oras discover --oci-layout oci-root:foo
Discovered 2 artifacts referencing jinzha1.azurecr.io/oci-root:foo
Digest: sha256:d415a6dda5872dedf2e080fded1dc40276fbfb71ce054f70bb57e2431d6a8b23

Artifact Type   Digest
type.artifact   sha256:3d050f891f461ce021dcf5b1bc6586c4d6d7e3087867cf859ee613e8b304dfb3
type.image      sha256:cd13e0cb5a8d5f42c3fbcfe53171ad25fc430879a190dc71121ec7b7f7b83386

# 2. Discovering referrers and filtering
$ oras discover --oci-layout oci-root:foo  --artifact-type type.image
Discovered 1 artifact referencing foo
Digest: sha256:d415a6dda5872dedf2e080fded1dc40276fbfb71ce054f70bb57e2431d6a8b23

Artifact Type   Digest
type.image      sha256:cd13e0cb5a8d5f42c3fbcfe53171ad25fc430879a190dc71121ec7b7f7b83386

Signed-off-by: Billy Zha jinzha1@microsoft.com

Signed-off-by: Billy Zha <jinzha1@microsoft.com>
@codecov-commenter
Copy link

codecov-commenter commented Jan 28, 2023

Codecov Report

Attention: Patch coverage is 64.91228% with 20 lines in your changes missing coverage. Please review.

Project coverage is 61.54%. Comparing base (9c91686) to head (3271b20).
Report is 436 commits behind head on main.

Files with missing lines Patch % Lines
internal/graph/graph.go 64.91% 13 Missing and 7 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #765      +/-   ##
==========================================
- Coverage   63.86%   61.54%   -2.32%     
==========================================
  Files          19       20       +1     
  Lines         714      801      +87     
==========================================
+ Hits          456      493      +37     
- Misses        225      268      +43     
- Partials       33       40       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@qweeah qweeah changed the title feat: support discovering in OCI image layout feat: support artifact discovering in OCI image layout Jan 28, 2023
Signed-off-by: Billy Zha <jinzha1@microsoft.com>
Signed-off-by: Billy Zha <jinzha1@microsoft.com>
Signed-off-by: Billy Zha <jinzha1@microsoft.com>
Signed-off-by: Billy Zha <jinzha1@microsoft.com>
@qweeah qweeah marked this pull request as ready for review January 28, 2023 09:28
Signed-off-by: Billy Zha <jinzha1@microsoft.com>
Signed-off-by: Billy Zha <jinzha1@microsoft.com>
Signed-off-by: Billy Zha <jinzha1@microsoft.com>
This reverts commit bf77ecc.

Signed-off-by: Billy Zha <jinzha1@microsoft.com>
This reverts commit f0fc6b8.

Signed-off-by: Billy Zha <jinzha1@microsoft.com>
Signed-off-by: Billy Zha <jinzha1@microsoft.com>
var fetched []byte
if rc, err := target.Fetch(ctx, node); err != nil {
return nil, err
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The else enclosing can be deleted.

Copy link
Contributor Author

@qweeah qweeah Jan 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If else is deleted, then rc will be undefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It reminds me that I can actually use https://pkg.go.dev/oras.land/oras-go/v2#FetchBytes to avoid reading from rc myself

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rc is not deferred to be closed.

})
if err != nil {
return nil, err
func fetchReferrers(ctx context.Context, target oras.ReadOnlyGraphTarget, desc ocispec.Descriptor, artifactType string) ([]ocispec.Descriptor, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put this function into a package so that we can have unit tests?

cmd/oras/discover.go Outdated Show resolved Hide resolved
cmd/oras/discover.go Outdated Show resolved Hide resolved
cmd/oras/discover.go Outdated Show resolved Hide resolved
cmd/oras/discover.go Outdated Show resolved Hide resolved
cmd/oras/discover.go Outdated Show resolved Hide resolved
cmd/oras/discover.go Outdated Show resolved Hide resolved
cmd/oras/discover.go Outdated Show resolved Hide resolved
cmd/oras/discover.go Outdated Show resolved Hide resolved
cmd/oras/discover.go Outdated Show resolved Hide resolved
cmd/oras/discover.go Outdated Show resolved Hide resolved
Signed-off-by: Billy Zha <jinzha1@microsoft.com>
Signed-off-by: Billy Zha <jinzha1@microsoft.com>
Signed-off-by: Billy Zha <jinzha1@microsoft.com>
Signed-off-by: Billy Zha <jinzha1@microsoft.com>
Signed-off-by: Billy Zha <jinzha1@microsoft.com>
Signed-off-by: Billy Zha <jinzha1@microsoft.com>
Signed-off-by: Billy Zha <jinzha1@microsoft.com>
internal/graph/graph.go Outdated Show resolved Hide resolved
internal/graph/graph.go Outdated Show resolved Hide resolved
internal/graph/graph.go Show resolved Hide resolved
Signed-off-by: Billy Zha <jinzha1@microsoft.com>
Copy link
Contributor

@shizhMSFT shizhMSFT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@shizhMSFT shizhMSFT merged commit 6e876c1 into oras-project:main Jan 29, 2023
TerryHowe pushed a commit to TerryHowe/oras that referenced this pull request Feb 2, 2023
)

Signed-off-by: Billy Zha <jinzha1@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support discovering referrers in OCI image layouts
4 participants