Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
34 changes: 22 additions & 12 deletions cmd/template/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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...)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
Loading