Skip to content

Commit

Permalink
feat: Support registry creds for image push
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmidyson committed Feb 23, 2022
1 parent 92b3fbf commit c52fdf8
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions cmd/push/imagebundle/image_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ func NewCommand(out output.Output) *cobra.Command {
imageBundleFile string
destRegistry string
destRegistrySkipTLSVerify bool
destRegistryUsername string
destRegistryPassword string
)

cmd := &cobra.Command{
Expand Down Expand Up @@ -78,18 +80,31 @@ func NewCommand(out output.Output) *cobra.Command {
skopeoRunner, skopeoCleanup := skopeo.NewRunner()
cleaner.AddCleanupFn(func() { _ = skopeoCleanup() })

skopeoStdout, skopeoStderr, err := skopeoRunner.AttemptToLoginToRegistry(
context.TODO(),
destRegistry,
)
if err != nil {
out.Infof("---skopeo stdout---:\n%s", skopeoStdout)
out.Infof("---skopeo stderr---:\n%s", skopeoStderr)
return fmt.Errorf("error logging in to target registry: %w", err)
var skopeoOpts []skopeo.SkopeoOption
if destRegistryUsername != "" && destRegistryPassword != "" {
skopeoOpts = append(
skopeoOpts,
skopeo.DestCredentials(
destRegistryUsername,
destRegistryPassword,
),
)
} else {
skopeoStdout, skopeoStderr, err := skopeoRunner.AttemptToLoginToRegistry(
context.TODO(),
destRegistry,
)
if err != nil {
out.Infof("---skopeo stdout---:\n%s", skopeoStdout)
out.Infof("---skopeo stderr---:\n%s", skopeoStderr)
return fmt.Errorf("error logging in to target registry: %w", err)
}
out.V(4).Infof("---skopeo stdout---:\n%s", skopeoStdout)
out.V(4).Infof("---skopeo stderr---:\n%s", skopeoStderr)
}

for _, registryConfig := range cfg {
skopeoOpts := []skopeo.SkopeoOption{skopeo.DisableSrcTLSVerify()}
skopeoOpts = append(skopeoOpts, skopeo.DisableSrcTLSVerify())
if destRegistrySkipTLSVerify {
skopeoOpts = append(skopeoOpts, skopeo.DisableDestTLSVerify())
}
Expand Down Expand Up @@ -132,6 +147,10 @@ func NewCommand(out output.Output) *cobra.Command {
_ = cmd.MarkFlagRequired("to-registry")
cmd.Flags().BoolVar(&destRegistrySkipTLSVerify, "to-registry-insecure-skip-tls-verify", false,
"Skip TLS verification of registry to push images to (use for http registries)")
cmd.Flags().StringVar(&destRegistryUsername, "to-registry-username", "",
"Username to use to log in to destination registry")
cmd.Flags().StringVar(&destRegistryPassword, "to-registry-password", "",
"Password to use to log in to destination registry")

return cmd
}

0 comments on commit c52fdf8

Please sign in to comment.