From e5220d67586d7d4b11f09c7a2f54d30c69ccff8e Mon Sep 17 00:00:00 2001 From: joohwan Date: Thu, 10 Sep 2026 11:11:43 +0800 Subject: [PATCH] feat(template): support private registry credentials for base image pulls --- cmd/template/build.go | 34 ++++++++++++++++++++++------------ go.mod | 2 +- go.sum | 2 ++ 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/cmd/template/build.go b/cmd/template/build.go index c644488..66a784d 100644 --- a/cmd/template/build.go +++ b/cmd/template/build.go @@ -18,18 +18,20 @@ const ( ) type buildFlags struct { - path string - dockerfile string - startCmd string - readyCmd string - cpuCount int - memoryMB int - cpuSet bool - memorySet bool - noCache bool - publish bool - tags []string - logLevel string + path string + dockerfile string + startCmd string + readyCmd string + cpuCount int + memoryMB int + cpuSet bool + memorySet bool + noCache bool + publish bool + tags []string + logLevel string + registryUsername string + registryPassword string } func newBuildCmd() *cobra.Command { @@ -68,6 +70,8 @@ func buildCommand(use string, aliases []string, short string) *cobra.Command { cmd.Flags().BoolVar(&flags.publish, "publish", false, "Publish after build") cmd.Flags().StringSliceVarP(&flags.tags, "tag", "t", nil, "Build tags") cmd.Flags().StringVar(&flags.logLevel, "level", "info", "Minimum build log level (debug, info, warn, error)") + cmd.Flags().StringVar(&flags.registryUsername, "registry-username", "", "Username for pulling the base image from a private registry") + cmd.Flags().StringVar(&flags.registryPassword, "registry-password", "", "Password for pulling the base image from a private registry") return cmd } @@ -105,6 +109,9 @@ func runBuild(name string, flags *buildFlags) error { if flags.startCmd == "" && flags.readyCmd != "" { return fmt.Errorf("both --cmd and --ready-cmd must be provided together") } + if (flags.registryUsername == "") != (flags.registryPassword == "") { + return fmt.Errorf("both --registry-username and --registry-password must be provided together") + } cfg, err := config.Load() if err != nil { @@ -137,6 +144,9 @@ func runBuild(name string, flags *buildFlags) error { if flags.publish { opts = append(opts, sdk.WithPublishTemplate()) } + if flags.registryUsername != "" { + opts = append(opts, sdk.WithBuildFromImageRegistry(flags.registryUsername, flags.registryPassword)) + } fmt.Println("\nBuilding sandbox template...") fmt.Println() info, err := client.BuildTemplate(context.Background(), builder, name, opts...) diff --git a/go.mod b/go.mod index 4bb41c3..b60d401 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/schollz/progressbar/v3 v3.19.1 github.com/spf13/cobra v1.10.2 github.com/stretchr/testify v1.11.1 - github.com/ucloud/ucloud-sandbox-sdk-go v0.0.0-20260901104032-07e3348267f2 + github.com/ucloud/ucloud-sandbox-sdk-go v0.0.0-20260910030832-8ef53e9144e2 golang.org/x/mod v0.40.0 golang.org/x/term v0.44.0 ) diff --git a/go.sum b/go.sum index 2e5ab91..69aa25b 100644 --- a/go.sum +++ b/go.sum @@ -50,6 +50,8 @@ github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/ucloud/ucloud-sandbox-sdk-go v0.0.0-20260901104032-07e3348267f2 h1:hW2cUdBNVfOcge59V9Wg1Kp6bGAT+V7dwl5aVGKU9dI= github.com/ucloud/ucloud-sandbox-sdk-go v0.0.0-20260901104032-07e3348267f2/go.mod h1:YrCrvJEqOBr33ToGyKcFB+ZcTY0EkueE4H0uyqNdsb8= +github.com/ucloud/ucloud-sandbox-sdk-go v0.0.0-20260910030832-8ef53e9144e2 h1:m9JyzdCMKqQh05bphya4OZLZUb1DIsWDmmqlZeFRtyg= +github.com/ucloud/ucloud-sandbox-sdk-go v0.0.0-20260910030832-8ef53e9144e2/go.mod h1:YrCrvJEqOBr33ToGyKcFB+ZcTY0EkueE4H0uyqNdsb8= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=