-
Notifications
You must be signed in to change notification settings - Fork 587
[WIP] Add ability to create multiple tags in one call. #2132
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 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,8 +21,8 @@ import ( | |
"github.com/google/go-containerregistry/pkg/v1/remote" | ||
) | ||
|
||
// Tag adds tag to the remote img. | ||
func Tag(img, tag string, opt ...Option) error { | ||
// Tag adds one or more tags to the remote img. | ||
func Tag(img string, tags any, opt ...Option) error { | ||
o := makeOptions(opt...) | ||
ref, err := name.ParseReference(img, o.Name...) | ||
if err != nil { | ||
|
@@ -33,7 +33,27 @@ func Tag(img, tag string, opt ...Option) error { | |
return fmt.Errorf("fetching %q: %w", img, err) | ||
} | ||
|
||
dst := ref.Context().Tag(tag) | ||
// Handle both single tag (string) and multiple tags ([]string) for backwards compatibility | ||
var tagList []string | ||
switch t := tags.(type) { | ||
case string: | ||
tagList = []string{t} | ||
case []string: | ||
tagList = t | ||
default: | ||
return fmt.Errorf("tags must be string or []string, got %T", tags) | ||
} | ||
|
||
// Apply each tag | ||
for i, tag := range tagList { | ||
dst := ref.Context().Tag(tag) | ||
if err := remote.Tag(dst, desc, o.Remote...); err != nil { | ||
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. One nice thing about tagging being done on only one tag is that we know exactly whether to continue or fail when tagging fails. When there are multiple tags requested and one fails, should we:
I don't have a super strong opinion, and failing right away like this is probably fine, but with single-tagging it's up to the caller what to do. I guess it's still up to them, and they could just keep using single-tagging. 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. yeah, that's what I was thinking about here |
||
if i > 0 { | ||
return fmt.Errorf("tagging %q with %q failed (successfully tagged with %v): %w", img, tag, tagList[:i], err) | ||
} | ||
return fmt.Errorf("tagging %q with %q: %w", img, tag, err) | ||
} | ||
} | ||
|
||
return remote.Tag(dst, desc, o.Remote...) | ||
return nil | ||
} |
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.
This is an API breaking change.
If we wanted to avoid this, we could maybe have
WithTags(string...) Option
, but even that might be kind of annoying.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.
good catch. I'll work on this
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.
New version pushed, let me know what you think.