Skip to content

Commit

Permalink
feat: deduplicate tags (ko-build#884)
Browse files Browse the repository at this point in the history
Signed-off-by: Nico Braun <rainbowstack@gmail.com>

Signed-off-by: Nico Braun <rainbowstack@gmail.com>
  • Loading branch information
bluebrown authored Nov 9, 2022
1 parent 140ac87 commit 5f75bcf
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkg/commands/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}

0 comments on commit 5f75bcf

Please sign in to comment.