Skip to content

Commit 8b099cb

Browse files
committed
Allow building with a specific registry, even without pushing.
1 parent 1c05014 commit 8b099cb

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

commands/build.go

+17-10
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"path/filepath"
1414
)
1515

16-
func getRegistry() (registryAddr string, registryInsecure bool, err error) {
16+
func getRegistry(cliContext *cli.Context) (registryAddr string, registryInsecure bool, err error) {
1717
provisioner, err := getProvisioner()
1818

1919
if err != nil {
@@ -39,12 +39,15 @@ func createBuildInterface(forceNoninteractive bool) build.Interface {
3939
func buildCommandAction(cliContext *cli.Context) error {
4040
registry := ""
4141
registryInsecure := false
42-
if cliContext.Bool("push") {
42+
if addr := cliContext.String("registry"); addr != "" {
43+
registry = addr
44+
} else if cliContext.Bool("push") {
4345
_, err := getProvisioner()
4446
if err != nil {
4547
return cli.NewExitError(fmt.Sprintf("you must be in an environment with a provisioner to use --push while building: %s", err.Error()), 1)
4648
}
47-
registry, registryInsecure, err = getRegistry()
49+
50+
registry, registryInsecure, err = getRegistry(cliContext)
4851
if err != nil {
4952
return cli.NewExitError(fmt.Sprintf("you specified --push, but a registry was not found: %s. Try \"sanic deploy\" first.", err.Error()), 1)
5053
}
@@ -108,12 +111,12 @@ func buildCommandAction(cliContext *cli.Context) error {
108111
jobs := make([]func(context.Context) error, 0, len(services))
109112

110113
builder := build.Builder{
111-
Registry: registry,
114+
Registry: registry,
112115
RegistryInsecure: registryInsecure,
113-
BuildTag: buildTag,
114-
Logger: buildLogger,
115-
Interface: buildInterface,
116-
DoPush: cliContext.Bool("push"),
116+
BuildTag: buildTag,
117+
Logger: buildLogger,
118+
Interface: buildInterface,
119+
DoPush: cliContext.Bool("push"),
117120
}
118121

119122
for _, service := range services {
@@ -159,11 +162,15 @@ var buildCommand = cli.Command{
159162
Usage: "pushes to the configured registry for the current environment instead of loading locally",
160163
},
161164
cli.StringFlag{
162-
Name: "tag,t",
165+
Name: "tag,t",
163166
Usage: "sets the tag of all built images to the specified one",
164167
},
168+
cli.StringFlag{
169+
Name: "registry",
170+
Usage: "sets the registry of all built images to the specified one (i.e., for use with --push)",
171+
},
165172
cli.BoolFlag{
166-
Name: "verbose",
173+
Name: "verbose",
167174
Usage: "enables verbose logging, mostly for sanic development",
168175
},
169176
},

0 commit comments

Comments
 (0)