mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-05 02:57:41 +08:00
bake: reset no-cache and pull if not set
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
parent
c4d07f67e3
commit
18095ee87b
@ -106,15 +106,20 @@ func bakeCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
|
||||
Use: "bake [OPTIONS] [TARGET...]",
|
||||
Aliases: []string{"f"},
|
||||
Short: "Build from a file",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
// reset to nil to avoid override is unset
|
||||
if !cmd.Flags().Lookup("no-cache").Changed {
|
||||
options.noCache = nil
|
||||
}
|
||||
if !cmd.Flags().Lookup("pull").Changed {
|
||||
options.pull = nil
|
||||
}
|
||||
return runBake(dockerCli, args, options)
|
||||
},
|
||||
}
|
||||
|
||||
flags := cmd.Flags()
|
||||
|
||||
cmd.RunE = func(cmd *cobra.Command, args []string) error {
|
||||
handleUnsetFlags(flags, &options)
|
||||
return runBake(dockerCli, args, options)
|
||||
}
|
||||
|
||||
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)")
|
||||
|
@ -70,18 +70,6 @@ type commonOptions struct {
|
||||
exportLoad bool
|
||||
}
|
||||
|
||||
func (o *commonOptions) Unset(s string) error {
|
||||
switch s {
|
||||
case "pull":
|
||||
o.noCache = nil
|
||||
case "no-cache":
|
||||
o.pull = nil
|
||||
default:
|
||||
return errors.Errorf("cannot unset flag %q", s)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func runBuild(dockerCli command.Cli, in buildOptions) error {
|
||||
if in.squash {
|
||||
return errors.Errorf("squash currently not implemented")
|
||||
@ -220,21 +208,6 @@ func buildTargets(ctx context.Context, dockerCli command.Cli, opts map[string]bu
|
||||
return err
|
||||
}
|
||||
|
||||
type unsetter interface {
|
||||
Unset(flagName string) error
|
||||
}
|
||||
|
||||
func handleUnsetFlags(flags *pflag.FlagSet, options unsetter) error {
|
||||
for _, name := range []string{"pull", "no-cache"} {
|
||||
if !flags.Lookup(name).Changed {
|
||||
if err := options.Unset(name); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func buildCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
|
||||
var options buildOptions
|
||||
|
||||
@ -243,17 +216,15 @@ func buildCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
|
||||
Aliases: []string{"b"},
|
||||
Short: "Start a build",
|
||||
Args: cli.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
options.contextPath = args[0]
|
||||
options.builder = rootOpts.builder
|
||||
return runBuild(dockerCli, options)
|
||||
},
|
||||
}
|
||||
|
||||
flags := cmd.Flags()
|
||||
|
||||
cmd.RunE = func(cmd *cobra.Command, args []string) error {
|
||||
options.contextPath = args[0]
|
||||
options.builder = rootOpts.builder
|
||||
handleUnsetFlags(flags, &options)
|
||||
return runBuild(dockerCli, options)
|
||||
}
|
||||
|
||||
flags.BoolVar(&options.exportPush, "push", false, "Shorthand for --output=type=registry")
|
||||
flags.BoolVar(&options.exportLoad, "load", false, "Shorthand for --output=type=docker")
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user