From 7c797327ab4ec994960dc42d660139eae2b3a772 Mon Sep 17 00:00:00 2001 From: Louis Blin <45168934+lbpdt@users.noreply.github.com> Date: Thu, 11 Mar 2021 12:31:13 +0000 Subject: [PATCH] makisu pull: add support for --registry-config This is useful to authenticate with the registry when pulling images. --- bin/makisu/cmd/build.go | 2 +- bin/makisu/cmd/pull.go | 28 ++++++++++++++++++++++------ bin/makisu/cmd/push.go | 2 +- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/bin/makisu/cmd/build.go b/bin/makisu/cmd/build.go index 3817850b..85fce480 100644 --- a/bin/makisu/cmd/build.go +++ b/bin/makisu/cmd/build.go @@ -101,7 +101,7 @@ func getBuildCmd() *buildCmd { buildCmd.PersistentFlags().StringArrayVar(&buildCmd.pushRegistries, "push", nil, "Registry to push image to") buildCmd.PersistentFlags().StringArrayVar(&buildCmd.replicas, "replica", nil, "Push targets with alternative full image names \"/:\"") - buildCmd.PersistentFlags().StringVar(&buildCmd.registryConfig, "registry-config", "", "Set build-time variables") + buildCmd.PersistentFlags().StringVar(&buildCmd.registryConfig, "registry-config", "", "Supply path to registry configuration file") buildCmd.PersistentFlags().StringVar(&buildCmd.destination, "dest", "", "Destination of the image tar") buildCmd.PersistentFlags().StringVar(&buildCmd.target, "target", "", "Set the target build stage to build.") diff --git a/bin/makisu/cmd/pull.go b/bin/makisu/cmd/pull.go index 44b32a2e..bd09723d 100644 --- a/bin/makisu/cmd/pull.go +++ b/bin/makisu/cmd/pull.go @@ -11,6 +11,7 @@ import ( "github.com/andres-erbsen/clock" "github.com/spf13/cobra" "github.com/uber/makisu/lib/docker/image" + "github.com/uber/makisu/lib/log" "github.com/uber/makisu/lib/registry" "github.com/uber/makisu/lib/snapshot" "github.com/uber/makisu/lib/storage" @@ -20,18 +21,19 @@ import ( type pullCmd struct { *cobra.Command - registry string - tag string - cacerts string - extract string + registryConfig string + registry string + tag string + cacerts string + extract string } func getPullCmd() *pullCmd { pullCmd := &pullCmd{ Command: &cobra.Command{ - Use: "pull --dest ", + Use: "pull --dest ", DisableFlagsInUseLine: true, - Short: "Pull docker image from registry into the storage directory of makisu.", + Short: "Pull docker image from registry into the storage directory of makisu.", }, } pullCmd.Args = func(cmd *cobra.Command, args []string) error { @@ -41,9 +43,15 @@ func getPullCmd() *pullCmd { return nil } pullCmd.Run = func(cmd *cobra.Command, args []string) { + if err := pullCmd.processFlags(); err != nil { + log.Errorf("failed to process flags: %s", err) + os.Exit(1) + } + pullCmd.Pull(args[0]) } + pullCmd.PersistentFlags().StringVar(&pullCmd.registryConfig, "registry-config", "", "Supply path to registry configuration file") pullCmd.PersistentFlags().StringVar(&pullCmd.registry, "registry", "index.docker.io", "The registry to pull the image from.") pullCmd.PersistentFlags().StringVar(&pullCmd.tag, "tag", "latest", "The tag of the image to pull.") pullCmd.PersistentFlags().StringVar(&pullCmd.cacerts, "cacerts", "/etc/ssl/certs", "The location of the CA certs to use for TLS authentication with the registry.") @@ -52,6 +60,14 @@ func getPullCmd() *pullCmd { return pullCmd } +func (cmd *pullCmd) processFlags() error { + if err := initRegistryConfig(cmd.registryConfig); err != nil { + return fmt.Errorf("failed to initialize registry configuration: %s", err) + } + + return nil +} + func (cmd *pullCmd) Pull(repository string) { store, err := storage.NewImageStore("/tmp/makisu-storage") if err != nil { diff --git a/bin/makisu/cmd/push.go b/bin/makisu/cmd/push.go index e9da82f3..d5420859 100644 --- a/bin/makisu/cmd/push.go +++ b/bin/makisu/cmd/push.go @@ -73,7 +73,7 @@ func getPushCmd() *pushCmd { pushCmd.PersistentFlags().StringArrayVar(&pushCmd.pushRegistries, "push", nil, "Registry to push image to") pushCmd.PersistentFlags().StringArrayVar(&pushCmd.replicas, "replica", nil, "Push targets with alternative full image names \"/:\"") - pushCmd.PersistentFlags().StringVar(&pushCmd.registryConfig, "registry-config", "", "Set build-time variables") + pushCmd.PersistentFlags().StringVar(&pushCmd.registryConfig, "registry-config", "", "Supply path to registry configuration file") pushCmd.MarkFlagRequired("tag") pushCmd.Flags().SortFlags = false