Skip to content

Commit

Permalink
Allow passing skip-tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Qasim Sarfraz committed Jun 9, 2020
1 parent 0e2fbca commit 88dd6aa
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions imagesync.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"os"
"strings"
"sync"
)

Expand Down Expand Up @@ -58,6 +59,10 @@ func Execute() error {
Usage: "Type of the destination docker registry",
Value: "insecure",
},
cli.StringFlag{
Name: "skip-tags",
Usage: "Comma separated list of tags to be skipped",
},
cli.BoolFlag{
Name: "overwrite",
Usage: "Use this to copy/override all the tags.",
Expand Down Expand Up @@ -102,6 +107,12 @@ func Execute() error {
return errors.WithMessage(err, "getting source tags")
}

// filter tags
shouldSkip := c.String("skip-tags")
if shouldSkip != "" {
srcTags = filterSourceTags(srcTags, strings.Split(shouldSkip, ","))
}

destTags, _ := docker.GetRepositoryTags(ctx, destSysCtx, destRegistry)

targetTags := targetTags(c.Bool("overwrite"), srcTags, destTags)
Expand Down Expand Up @@ -199,6 +210,26 @@ func (ci *copyImageInput) copyImage(tag string) error {
return nil
}

func filterSourceTags(src []string, shouldSkip []string) []string {
var result []string
for _, tag := range src {
if contains(shouldSkip, tag) {
continue
}
result = append(result, tag)
}
return result
}

func contains(slice []string, str string) bool {
for _, item := range slice {
if item == str {
return true
}
}
return false
}

func targetTags(overwrite bool, src, dest []string) []string {
if overwrite {
return src
Expand Down

0 comments on commit 88dd6aa

Please sign in to comment.