diff --git a/pkg/commands/resolver.go b/pkg/commands/resolver.go index 2b341c7d62..e2b3d16c99 100644 --- a/pkg/commands/resolver.go +++ b/pkg/commands/resolver.go @@ -167,6 +167,8 @@ func NewPublisher(po *options.PublishOptions) (publish.Interface, error) { } func makePublisher(po *options.PublishOptions) (publish.Interface, error) { + // use each tag only once + po.Tags = unique(po.Tags) // Create the publish.Interface that we will use to publish image references // to either a docker daemon or a container image registry. innerPublisher, err := func() (publish.Interface, error) { @@ -470,3 +472,19 @@ func resolveFile( return buf.Bytes(), nil } + +// create a set from the input slice +// preserving the order of unique elements +func unique(ss []string) []string { + var ( + seen = make(map[string]struct{}, len(ss)) + uniq = make([]string, 0, len(ss)) + ) + for _, s := range ss { + if _, ok := seen[s]; !ok { + seen[s] = struct{}{} + uniq = append(uniq, s) + } + } + return uniq +}