Skip to content
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

Allow multiple destinations #184

Merged
merged 2 commits into from
May 17, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions cmd/executor/cmd/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@ import (
"strings"
)

// The buildArg type is used to pass in multiple --build-arg flags
type buildArg []string
// This type is used to supported passing in multiple flags
type multiArg []string

// Now, for our new type, implement the two methods of
// the flag.Value interface...
// The first method is String() string
func (b *buildArg) String() string {
func (b *multiArg) String() string {
return strings.Join(*b, ",")
}

// The second method is Set(value string) error
func (b *buildArg) Set(value string) error {
logrus.Infof("appending to build args %s", value)
func (b *multiArg) Set(value string) error {
logrus.Infof("appending to multi args %s", value)
*b = append(*b, value)
return nil
}

func (b *buildArg) Type() string {
return "build-arg type"
func (b *multiArg) Type() string {
return "multi-arg type"
}
15 changes: 9 additions & 6 deletions cmd/executor/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,22 @@ import (

var (
dockerfilePath string
destination string
destinations multiArg
srcContext string
snapshotMode string
bucket string
dockerInsecureSkipTLSVerify bool
logLevel string
force bool
buildArgs buildArg
buildArgs multiArg
tarPath string
)

func init() {
RootCmd.PersistentFlags().StringVarP(&dockerfilePath, "dockerfile", "f", "Dockerfile", "Path to the dockerfile to be built.")
RootCmd.PersistentFlags().StringVarP(&srcContext, "context", "c", "/workspace/", "Path to the dockerfile build context.")
RootCmd.PersistentFlags().StringVarP(&bucket, "bucket", "b", "", "Name of the GCS bucket from which to access build context as tarball.")
RootCmd.PersistentFlags().StringVarP(&destination, "destination", "d", "", "Registry the final image should be pushed to (ex: gcr.io/test/example:latest)")
RootCmd.PersistentFlags().VarP(&destinations, "destination", "d", "Registry the final image should be pushed to. Set it repeatedly for multiple destinations.")
RootCmd.MarkPersistentFlagRequired("destination")
RootCmd.PersistentFlags().StringVarP(&snapshotMode, "snapshotMode", "", "full", "Set this flag to change the file attributes inspected during snapshotting")
RootCmd.PersistentFlags().VarP(&buildArgs, "build-arg", "", "This flag allows you to pass in ARG values at build time. Set it repeatedly for multiple values.")
Expand Down Expand Up @@ -84,10 +84,13 @@ var RootCmd = &cobra.Command{
logrus.Error(err)
os.Exit(1)
}
if err := executor.DoPush(ref, image, destination, tarPath); err != nil {
logrus.Error(err)
os.Exit(1)

for _, destination := range destinations {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we instead pass the destinations into DoPush, and have the for loop there?

if err := executor.DoPush(ref, image, destination, tarPath); err != nil {
logrus.Error(err)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want to add the os.Exit(1) here!

}

},
}

Expand Down