-
Notifications
You must be signed in to change notification settings - Fork 717
Support push --all-tags to push all tags
#4627
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ import ( | |
| "net/http" | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
|
|
||
| "github.com/opencontainers/go-digest" | ||
| ocispec "github.com/opencontainers/image-spec/specs-go/v1" | ||
|
|
@@ -61,7 +62,18 @@ func Push(ctx context.Context, client *containerd.Client, rawRef string, options | |
| return err | ||
| } | ||
|
|
||
| // Disallow tag (or digest) together with --all-tags | ||
| if options.AllTags { | ||
| if parsedReference.Tag != "" || parsedReference.Digest != "" { | ||
| return fmt.Errorf("tag can't be used with --all-tags/-a") | ||
| } | ||
| } | ||
|
|
||
| if parsedReference.Protocol != "" { | ||
| if options.AllTags { | ||
| return fmt.Errorf("--all-tags is not supported for %q references", parsedReference.Protocol) | ||
| } | ||
|
|
||
| if parsedReference.Protocol != referenceutil.IPFSProtocol { | ||
| return fmt.Errorf("ipfs scheme is only supported but got %q", parsedReference.Protocol) | ||
| } | ||
|
|
@@ -105,10 +117,43 @@ func Push(ctx context.Context, client *containerd.Client, rawRef string, options | |
| return nil | ||
| } | ||
|
|
||
| parsedReference, err = referenceutil.Parse(rawRef) | ||
| if err != nil { | ||
| return err | ||
| // Handle --all-tags | ||
| if options.AllTags { | ||
| repo := "" | ||
| if parsedReference.Domain != "" { | ||
| repo = parsedReference.Domain + "/" | ||
| } | ||
| repo += parsedReference.Path | ||
|
|
||
| imgList, err := client.ImageService().List(ctx) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| var tagRefs []string | ||
| for _, img := range imgList { | ||
| if strings.HasPrefix(img.Name, repo+":") { | ||
| tagRefs = append(tagRefs, img.Name) | ||
| } | ||
| } | ||
|
Comment on lines
+133
to
+138
Member
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. The prefix matching is too broad and can match unintended images. For example, if repository is
Author
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. If repo is |
||
|
|
||
| if len(tagRefs) == 0 { | ||
| return fmt.Errorf("no local tags found for repository %q", repo) | ||
| } | ||
|
|
||
| for i, tagRef := range tagRefs { | ||
| tagOpts := options | ||
| tagOpts.AllTags = false // avoid infinite recursion | ||
| tagOpts.SkipSoci = i > 0 // avoid SOCI indexing for the same image | ||
|
|
||
| if err := Push(ctx, client, tagRef, tagOpts); err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| ref := parsedReference.String() | ||
| refDomain := parsedReference.Domain | ||
|
|
||
|
|
@@ -209,7 +254,7 @@ func Push(ctx context.Context, client *containerd.Client, rawRef string, options | |
| options.SignOptions); err != nil { | ||
| return err | ||
| } | ||
| if options.GOptions.Snapshotter == "soci" { | ||
| if options.GOptions.Snapshotter == "soci" && !options.SkipSoci { | ||
| if err = snapshotterutil.CreateSociIndexV1(ref, options.GOptions, options.AllPlatforms, options.Platforms, options.SociOptions); err != nil { | ||
| return err | ||
| } | ||
|
|
||
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.
Currently, iff user runs nerdctl push
myrepo:v1 --all-tags, the tag:v1is silently ignored. It should return an error like docker does: https://github.com/docker/cli/blob/1a1a4fc478fcd0131f3f3225b98faa5bd16dc51e/cli/command/image/push.go#L102