diff --git a/commands/bake.go b/commands/bake.go index 68a61e8d..f1408d96 100644 --- a/commands/bake.go +++ b/commands/bake.go @@ -74,7 +74,7 @@ func runBake(dockerCli command.Cli, targets []string, in bakeOptions) error { contextPathHash, _ := os.Getwd() - return buildTargets(ctx, dockerCli, bo, in.progress, contextPathHash) + return buildTargets(ctx, dockerCli, bo, in.progress, contextPathHash, in.builder) } func defaultFiles() ([]string, error) { @@ -119,7 +119,7 @@ func bakeCmd(dockerCli command.Cli) *cobra.Command { 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) + commonBuildFlags(&options.commonOptions, flags) return cmd } diff --git a/commands/build.go b/commands/build.go index 153a4c1d..26eb81cd 100644 --- a/commands/build.go +++ b/commands/build.go @@ -63,11 +63,13 @@ type buildOptions struct { } type commonOptions struct { + builderOptions noCache *bool progress string pull *bool exportPush bool exportLoad bool + builder string } func runBuild(dockerCli command.Cli, in buildOptions) error { @@ -191,11 +193,11 @@ func runBuild(dockerCli command.Cli, in buildOptions) error { contextPathHash = in.contextPath } - return buildTargets(ctx, dockerCli, map[string]build.Options{"default": opts}, in.progress, contextPathHash) + return buildTargets(ctx, dockerCli, map[string]build.Options{"default": opts}, in.progress, contextPathHash, in.builder) } -func buildTargets(ctx context.Context, dockerCli command.Cli, opts map[string]build.Options, progressMode, contextPathHash string) error { - dis, err := getDefaultDrivers(ctx, dockerCli, contextPathHash) +func buildTargets(ctx context.Context, dockerCli command.Cli, opts map[string]build.Options, progressMode, contextPathHash, instance string) error { + dis, err := getInstanceOrDefault(ctx, dockerCli, instance, contextPathHash) if err != nil { return err } @@ -297,12 +299,13 @@ func buildCmd(dockerCli command.Cli) *cobra.Command { flags.StringArrayVarP(&options.outputs, "output", "o", []string{}, "Output destination (format: type=local,dest=path)") - commonFlags(&options.commonOptions, flags) + commonBuildFlags(&options.commonOptions, flags) return cmd } -func commonFlags(options *commonOptions, flags *pflag.FlagSet) { +func commonBuildFlags(options *commonOptions, flags *pflag.FlagSet) { + builderFlags(&options.builderOptions, flags) flags.Var(flagutil.Tristate(options.noCache), "no-cache", "Do not use cache when building the image") flags.StringVar(&options.progress, "progress", "auto", "Set type of progress output (auto, plain, tty). Use plain to show container output") flags.Var(flagutil.Tristate(options.pull), "pull", "Always attempt to pull a newer version of the image") diff --git a/commands/builder.go b/commands/builder.go new file mode 100644 index 00000000..22a4b29b --- /dev/null +++ b/commands/builder.go @@ -0,0 +1,11 @@ +package commands + +import "github.com/spf13/pflag" + +type builderOptions struct { + builder string +} + +func builderFlags(options *builderOptions, flags *pflag.FlagSet) { + flags.StringVar(&options.builder, "builder", "", "Override the configured builder instance") +} diff --git a/commands/diskusage.go b/commands/diskusage.go index 3ae434b7..7fe5a02b 100644 --- a/commands/diskusage.go +++ b/commands/diskusage.go @@ -18,6 +18,7 @@ import ( ) type duOptions struct { + builderOptions filter opts.FilterOpt verbose bool } @@ -30,7 +31,7 @@ func runDiskUsage(dockerCli command.Cli, opts duOptions) error { return err } - dis, err := getDefaultDrivers(ctx, dockerCli, "") + dis, err := getInstanceOrDefault(ctx, dockerCli, opts.builder, "") if err != nil { return err } @@ -111,6 +112,7 @@ func duCmd(dockerCli command.Cli) *cobra.Command { } flags := cmd.Flags() + builderFlags(&options.builderOptions, flags) flags.Var(&options.filter, "filter", "Provide filter values") flags.BoolVar(&options.verbose, "verbose", false, "Provide a more verbose output") diff --git a/commands/prune.go b/commands/prune.go index a2035a17..6ce54c88 100644 --- a/commands/prune.go +++ b/commands/prune.go @@ -21,6 +21,7 @@ import ( ) type pruneOptions struct { + builderOptions all bool filter opts.FilterOpt keepStorage opts.MemBytes @@ -53,7 +54,7 @@ func runPrune(dockerCli command.Cli, opts pruneOptions) error { return nil } - dis, err := getDefaultDrivers(ctx, dockerCli, "") + dis, err := getInstanceOrDefault(ctx, dockerCli, opts.builder, "") if err != nil { return err } diff --git a/commands/util.go b/commands/util.go index 68bfcaa9..5b9ea9b1 100644 --- a/commands/util.go +++ b/commands/util.go @@ -247,6 +247,27 @@ func clientForEndpoint(dockerCli command.Cli, name string) (dockerclient.APIClie return dockerclient.NewClientWithOpts(clientOpts...) } +func getInstanceOrDefault(ctx context.Context, dockerCli command.Cli, instance, contextPathHash string) ([]build.DriverInfo, error) { + if instance != "" { + return getInstanceByName(ctx, dockerCli, instance, contextPathHash) + } + return getDefaultDrivers(ctx, dockerCli, contextPathHash) +} + +func getInstanceByName(ctx context.Context, dockerCli command.Cli, instance, contextPathHash string) ([]build.DriverInfo, error) { + txn, release, err := getStore(dockerCli) + if err != nil { + return nil, err + } + defer release() + + ng, err := txn.NodeGroupByName(instance) + if err != nil { + return nil, err + } + return driversForNodeGroup(ctx, dockerCli, ng, contextPathHash) +} + // getDefaultDrivers returns drivers based on current cli config func getDefaultDrivers(ctx context.Context, dockerCli command.Cli, contextPathHash string) ([]build.DriverInfo, error) { txn, release, err := getStore(dockerCli)