Skip to content

Commit

Permalink
Enable to run build and invoke in background
Browse files Browse the repository at this point in the history
Signed-off-by: Kohei Tokunaga <[email protected]>
  • Loading branch information
ktock committed Oct 21, 2022
1 parent 1bb375f commit a88b3f5
Show file tree
Hide file tree
Showing 31 changed files with 5,047 additions and 641 deletions.
1 change: 1 addition & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
- lint
- validate-vendor
- validate-docs
- validate-generated-files
steps:
-
name: Checkout
Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ install: binaries
release:
./hack/release

validate-all: lint test validate-vendor validate-docs
validate-all: lint test validate-vendor validate-docs validate-generated-files

lint:
$(BUILDX_CMD) bake lint
Expand All @@ -44,6 +44,9 @@ validate-docs:
validate-authors:
$(BUILDX_CMD) bake validate-authors

validate-generated-files:
./hack/validate-generated-files

test-driver:
./hack/test-driver

Expand All @@ -59,4 +62,7 @@ authors:
mod-outdated:
$(BUILDX_CMD) bake mod-outdated

generated-files:
./hack/update-generated-files

.PHONY: shell binaries binaries-cross install release validate-all lint validate-vendor validate-docs validate-authors vendor docs authors
44 changes: 24 additions & 20 deletions commands/bake.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/containerd/containerd/platforms"
"github.com/docker/buildx/bake"
"github.com/docker/buildx/build"
builderapi "github.com/docker/buildx/commands/builder/pb"
"github.com/docker/buildx/util/confutil"
"github.com/docker/buildx/util/progress"
"github.com/docker/buildx/util/tracing"
Expand All @@ -22,10 +23,10 @@ type bakeOptions struct {
files []string
overrides []string
printOnly bool
commonOptions
builderapi.CommonOptions
}

func runBake(dockerCli command.Cli, targets []string, in bakeOptions) (err error) {
func runBake(dockerCli command.Cli, targets []string, in bakeOptions, cFlags commonFlags) (err error) {
ctx := appcontext.Context()

ctx, end, err := tracing.TraceCurrentCommand(ctx, "bake")
Expand Down Expand Up @@ -57,25 +58,25 @@ func runBake(dockerCli command.Cli, targets []string, in bakeOptions) (err error
}

overrides := in.overrides
if in.exportPush {
if in.exportLoad {
if in.ExportPush {
if in.ExportLoad {
return errors.Errorf("push and load may not be set together at the moment")
}
overrides = append(overrides, "*.push=true")
} else if in.exportLoad {
} else if in.ExportLoad {
overrides = append(overrides, "*.output=type=docker")
}
if in.noCache != nil {
overrides = append(overrides, fmt.Sprintf("*.no-cache=%t", *in.noCache))
if cFlags.noCache != nil {
overrides = append(overrides, fmt.Sprintf("*.no-cache=%t", *cFlags.noCache))
}
if in.pull != nil {
overrides = append(overrides, fmt.Sprintf("*.pull=%t", *in.pull))
if cFlags.pull != nil {
overrides = append(overrides, fmt.Sprintf("*.pull=%t", *cFlags.pull))
}
contextPathHash, _ := os.Getwd()

ctx2, cancel := context.WithCancel(context.TODO())
defer cancel()
printer := progress.NewPrinter(ctx2, os.Stderr, os.Stderr, in.progress)
printer := progress.NewPrinter(ctx2, os.Stderr, os.Stderr, cFlags.progress)

defer func() {
if printer != nil {
Expand All @@ -86,7 +87,7 @@ func runBake(dockerCli command.Cli, targets []string, in bakeOptions) (err error
}
}()

dis, err := getInstanceOrDefault(ctx, dockerCli, in.builder, contextPathHash)
dis, err := getInstanceOrDefault(ctx, dockerCli, in.Builder, contextPathHash)
if err != nil {
return err
}
Expand Down Expand Up @@ -150,12 +151,12 @@ func runBake(dockerCli command.Cli, targets []string, in bakeOptions) (err error
return wrapBuildError(err, true)
}

if len(in.metadataFile) > 0 {
if len(in.MetadataFile) > 0 {
dt := make(map[string]interface{})
for t, r := range resp {
dt[t] = decodeExporterResponse(r.ExporterResponse)
}
if err := writeMetadataFile(in.metadataFile, dt); err != nil {
if err := writeMetadataFile(in.MetadataFile, dt); err != nil {
return err
}
}
Expand All @@ -165,6 +166,7 @@ func runBake(dockerCli command.Cli, targets []string, in bakeOptions) (err error

func bakeCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
var options bakeOptions
var cFlags commonFlags

cmd := &cobra.Command{
Use: "bake [OPTIONS] [TARGET...]",
Expand All @@ -173,25 +175,27 @@ func bakeCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
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
cFlags.noCache = nil
}
if !cmd.Flags().Lookup("pull").Changed {
options.pull = nil
cFlags.pull = nil
}
options.commonOptions.builder = rootOpts.builder
return runBake(dockerCli, args, options)
options.Builder = rootOpts.builder
options.MetadataFile = cFlags.metadataFile
// Other common flags (noCache, pull and progress) are processed in runBake function.
return runBake(dockerCli, args, options, cFlags)
},
}

flags := cmd.Flags()

flags.StringArrayVarP(&options.files, "file", "f", []string{}, "Build definition file")
flags.BoolVar(&options.exportLoad, "load", false, `Shorthand for "--set=*.output=type=docker"`)
flags.BoolVar(&options.ExportLoad, "load", false, `Shorthand for "--set=*.output=type=docker"`)
flags.BoolVar(&options.printOnly, "print", false, "Print the options without building")
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.StringArrayVar(&options.overrides, "set", nil, `Override target value (e.g., "targetpattern.key=value")`)

commonBuildFlags(&options.commonOptions, flags)
commonBuildFlags(&cFlags, flags)

return cmd
}
Loading

0 comments on commit a88b3f5

Please sign in to comment.