Skip to content

Commit

Permalink
Implement ability to load images by default in non-Docker build drivers.
Browse files Browse the repository at this point in the history
This eases build driver migrations, as it allows aligning the default behavior.

See also https://docs.docker.com/build/drivers/

Signed-off-by: Niklas Gehlen <niklas@namespacelabs.com>
  • Loading branch information
n-g committed Feb 22, 2024
1 parent ccfcf4b commit de09615
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,18 @@ func noDefaultLoad() bool {
return b
}

func DefaultLoad() bool {
v, ok := os.LookupEnv("BUILDX_DEFAULT_LOAD")
if !ok {
return false
}
b, err := strconv.ParseBool(v)
if err != nil {
logrus.Warnf("invalid non-bool value for BUILDX_DEFAULT_LOAD: %s", v)
}
return b
}

// handle https://github.com/moby/moby/pull/10858
func handleLowercaseDockerfile(dir, p string) string {
if filepath.Base(p) != "Dockerfile" {
Expand Down
9 changes: 9 additions & 0 deletions controller/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,15 @@ func RunBuild(ctx context.Context, dockerCli command.Cli, in controllerapi.Build
}
}

// ENV-guarded ability load images by default if no other output is specified.
// This is useful when migrating from Docker buildx drivers to others, as it aligns the default behavior.
if build.DefaultLoad() && len(outputs) == 0 && len(opts.Tags) > 0 {
outputs = []client.ExportEntry{{
Type: "docker",
Attrs: map[string]string{},
}}
}

annotations, err := buildflags.ParseAnnotations(in.Annotations)
if err != nil {
return nil, nil, err
Expand Down

0 comments on commit de09615

Please sign in to comment.