mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-29 08:57:44 +08:00
Add option to build/bake to override instance
This helps prevent race conditions with concurrent build invocations. Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
parent
d89e3f3014
commit
213d3af3b0
@ -74,7 +74,7 @@ func runBake(dockerCli command.Cli, targets []string, in bakeOptions) error {
|
|||||||
|
|
||||||
contextPathHash, _ := os.Getwd()
|
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) {
|
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.exportPush, "push", false, "Shorthand for --set=*.output=type=registry")
|
||||||
flags.BoolVar(&options.exportLoad, "load", false, "Shorthand for --set=*.output=type=docker")
|
flags.BoolVar(&options.exportLoad, "load", false, "Shorthand for --set=*.output=type=docker")
|
||||||
|
|
||||||
commonFlags(&options.commonOptions, flags)
|
commonBuildFlags(&options.commonOptions, flags)
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
@ -63,11 +63,13 @@ type buildOptions struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type commonOptions struct {
|
type commonOptions struct {
|
||||||
|
builderOptions
|
||||||
noCache *bool
|
noCache *bool
|
||||||
progress string
|
progress string
|
||||||
pull *bool
|
pull *bool
|
||||||
exportPush bool
|
exportPush bool
|
||||||
exportLoad bool
|
exportLoad bool
|
||||||
|
builder string
|
||||||
}
|
}
|
||||||
|
|
||||||
func runBuild(dockerCli command.Cli, in buildOptions) error {
|
func runBuild(dockerCli command.Cli, in buildOptions) error {
|
||||||
@ -191,11 +193,11 @@ func runBuild(dockerCli command.Cli, in buildOptions) error {
|
|||||||
contextPathHash = in.contextPath
|
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 {
|
func buildTargets(ctx context.Context, dockerCli command.Cli, opts map[string]build.Options, progressMode, contextPathHash, instance string) error {
|
||||||
dis, err := getDefaultDrivers(ctx, dockerCli, contextPathHash)
|
dis, err := getInstanceOrDefault(ctx, dockerCli, instance, contextPathHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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)")
|
flags.StringArrayVarP(&options.outputs, "output", "o", []string{}, "Output destination (format: type=local,dest=path)")
|
||||||
|
|
||||||
commonFlags(&options.commonOptions, flags)
|
commonBuildFlags(&options.commonOptions, flags)
|
||||||
|
|
||||||
return cmd
|
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.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.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")
|
flags.Var(flagutil.Tristate(options.pull), "pull", "Always attempt to pull a newer version of the image")
|
||||||
|
11
commands/builder.go
Normal file
11
commands/builder.go
Normal file
@ -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")
|
||||||
|
}
|
@ -18,6 +18,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type duOptions struct {
|
type duOptions struct {
|
||||||
|
builderOptions
|
||||||
filter opts.FilterOpt
|
filter opts.FilterOpt
|
||||||
verbose bool
|
verbose bool
|
||||||
}
|
}
|
||||||
@ -30,7 +31,7 @@ func runDiskUsage(dockerCli command.Cli, opts duOptions) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
dis, err := getDefaultDrivers(ctx, dockerCli, "")
|
dis, err := getInstanceOrDefault(ctx, dockerCli, opts.builder, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -111,6 +112,7 @@ func duCmd(dockerCli command.Cli) *cobra.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
flags := cmd.Flags()
|
flags := cmd.Flags()
|
||||||
|
builderFlags(&options.builderOptions, flags)
|
||||||
flags.Var(&options.filter, "filter", "Provide filter values")
|
flags.Var(&options.filter, "filter", "Provide filter values")
|
||||||
flags.BoolVar(&options.verbose, "verbose", false, "Provide a more verbose output")
|
flags.BoolVar(&options.verbose, "verbose", false, "Provide a more verbose output")
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type pruneOptions struct {
|
type pruneOptions struct {
|
||||||
|
builderOptions
|
||||||
all bool
|
all bool
|
||||||
filter opts.FilterOpt
|
filter opts.FilterOpt
|
||||||
keepStorage opts.MemBytes
|
keepStorage opts.MemBytes
|
||||||
@ -53,7 +54,7 @@ func runPrune(dockerCli command.Cli, opts pruneOptions) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
dis, err := getDefaultDrivers(ctx, dockerCli, "")
|
dis, err := getInstanceOrDefault(ctx, dockerCli, opts.builder, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -247,6 +247,27 @@ func clientForEndpoint(dockerCli command.Cli, name string) (dockerclient.APIClie
|
|||||||
return dockerclient.NewClientWithOpts(clientOpts...)
|
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
|
// getDefaultDrivers returns drivers based on current cli config
|
||||||
func getDefaultDrivers(ctx context.Context, dockerCli command.Cli, contextPathHash string) ([]build.DriverInfo, error) {
|
func getDefaultDrivers(ctx context.Context, dockerCli command.Cli, contextPathHash string) ([]build.DriverInfo, error) {
|
||||||
txn, release, err := getStore(dockerCli)
|
txn, release, err := getStore(dockerCli)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user