diff --git a/README.md b/README.md index d2a7af48..175d7d69 100644 --- a/README.md +++ b/README.md @@ -507,10 +507,12 @@ Options: | Flag | Description | | --- | --- | | -f, --file stringArray | Build definition file +| --load | Shorthand for --set=*.output=type=docker | --no-cache | Do not use cache when building the image | --print | Print the options without building | --progress string | Set type of progress output (auto, plain, tty). Use plain to show container output (default "auto") | --pull | Always attempt to pull a newer version of the image +| --push | Shorthand for --set=*.output=type=registry | --set stringArray | Override target value (eg: targetpattern.key=value) #### `-f, --file FILE` diff --git a/commands/bake.go b/commands/bake.go index 660bb6fd..fa1daf35 100644 --- a/commands/bake.go +++ b/commands/bake.go @@ -37,7 +37,17 @@ func runBake(dockerCli command.Cli, targets []string, in bakeOptions) error { targets = []string{"default"} } - m, err := bake.ReadTargets(ctx, in.files, targets, in.overrides) + overrides := in.overrides + if in.exportPush { + if in.exportLoad { + return errors.Errorf("push and load may not be set together at the moment") + } + overrides = append(overrides, "*.output=type=registry") + } else if in.exportLoad { + overrides = append(overrides, "*.output=type=docker") + } + + m, err := bake.ReadTargets(ctx, in.files, targets, overrides) if err != nil { return err } @@ -100,6 +110,8 @@ func bakeCmd(dockerCli command.Cli) *cobra.Command { flags.StringArrayVarP(&options.files, "file", "f", []string{}, "Build definition file") flags.BoolVar(&options.printOnly, "print", false, "Print the options without building") flags.StringArrayVar(&options.overrides, "set", nil, "Override target value (eg: targetpattern.key=value)") + flags.BoolVar(&options.exportPush, "push", false, "Shorthand for --set=*.output=type=registry") + flags.BoolVar(&options.exportLoad, "load", false, "Shorthand for --set=*.output=type=docker") commonFlags(&options.commonOptions, flags) diff --git a/commands/build.go b/commands/build.go index 1e865de3..86274df0 100644 --- a/commands/build.go +++ b/commands/build.go @@ -38,9 +38,6 @@ type buildOptions struct { extraHosts []string networkMode string - exportPush bool - exportLoad bool - // unimplemented squash bool quiet bool @@ -65,9 +62,11 @@ type buildOptions struct { } type commonOptions struct { - noCache bool - progress string - pull bool + noCache bool + progress string + pull bool + exportPush bool + exportLoad bool } func runBuild(dockerCli command.Cli, in buildOptions) error {