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: Add ability query tags for oras repo tags command #800

Merged
merged 8 commits into from
Feb 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions cmd/oras/repository/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ Example - Show tags of the target OCI layout folder 'layout-dir':

Example - Show tags of the target OCI layout archive 'layout.tar':
oras repo tags --oci-layout layout.tar

Example - Show tags associated with a particular tagged resource:
oras repo tags localhost:5000/hello:latest

Example - Show tags associated with a digest:
oras repo tags localhost:5000/hello@sha256:c551125a624189cece9135981621f3f3144564ddabe14b523507bf74c2281d9b
`,
Args: cobra.ExactArgs(1),
Aliases: []string{"show-tags"},
Expand All @@ -73,19 +79,43 @@ Example - Show tags of the target OCI layout archive 'layout.tar':
}

func showTags(opts showTagsOptions) error {
ctx, _ := opts.SetLoggerLevel()
ctx, logger := opts.SetLoggerLevel()
finder, err := opts.NewReadonlyTarget(ctx, opts.Common)
if err != nil {
return err
}
filter := ""
if opts.Reference != "" {
return fmt.Errorf("unexpected tag or digest %q found in repository reference %q", opts.Reference, opts.RawReference)
_, err := digest.Parse(opts.Reference)
if err == nil {
filter = opts.Reference
} else {
desc, err := finder.Resolve(ctx, opts.Reference)
if err != nil {
return err
}
filter = desc.Digest.String()
}
logger.Infof("[Preview] Querying tags associated to %s, it may take a while.\n", filter)
}
return finder.Tags(ctx, opts.last, func(tags []string) error {
for _, tag := range tags {
if opts.excludeDigestTag && isDigestTag(tag) {
continue
}
if filter != "" {
if tag == opts.Reference {
fmt.Println(tag)
continue
}
desc, err := finder.Resolve(ctx, tag)
qweeah marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}
if desc.Digest.String() != filter {
continue
}
}
fmt.Println(tag)
}
return nil
Expand Down