Skip to content
This repository has been archived by the owner on May 4, 2021. It is now read-only.

Commit

Permalink
makisu pull: add support for --registry-config
Browse files Browse the repository at this point in the history
This is useful to authenticate with the registry when pulling images.
  • Loading branch information
lbpdt committed Mar 16, 2021
1 parent 7d88e9f commit 470bc53
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion bin/makisu/cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 \"<registry>/<repo>:<tag>\"")
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.")
Expand Down
28 changes: 22 additions & 6 deletions bin/makisu/cmd/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 <destination of rootfs> <image repository>",
Use: "pull --dest <destination of rootfs> <image repository>",
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 {
Expand All @@ -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.")
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion bin/makisu/cmd/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 \"<registry>/<repo>:<tag>\"")
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
Expand Down

0 comments on commit 470bc53

Please sign in to comment.