Skip to content

Commit

Permalink
bake: allow overriding no-cache and pull per target via --set
Browse files Browse the repository at this point in the history
Signed-off-by: Tibor Vass <tibor@docker.com>
  • Loading branch information
Tibor Vass committed Apr 21, 2020
1 parent 70209e1 commit 5454b14
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -568,6 +568,9 @@ docker buildx bake --set foo*.args.mybuildarg=value # overrides build arg for al
docker buildx bake --set *.platform=linux/arm64 # overrides platform for all targets
```

Complete list of overridable fields:
args, cache-from, cache-to, context, dockerfile, labels, no-cache, output, platform, pull, secrets, ssh, tags, target

#### File definition

In addition to compose files, bake supports a JSON and an equivalent HCL file format for defining build groups and targets.
Expand Down
18 changes: 18 additions & 0 deletions bake/bake.go
Expand Up @@ -5,6 +5,7 @@ import (
"io/ioutil"
"os"
"path"
"strconv"
"strings"

"github.com/docker/buildx/build"
Expand Down Expand Up @@ -194,6 +195,21 @@ func (c Config) newOverrides(v []string) (map[string]Target, error) {
t.Platforms = append(t.Platforms, parts[1])
case "output":
t.Outputs = append(t.Outputs, parts[1])
case "no-cache":
noCache, err := strconv.ParseBool(parts[1])
if err != nil {
return errors.Errorf("invalid value %s for boolean key no-cache", parts[1])
}
t.NoCache = noCache
case "pull":
pull, err := strconv.ParseBool(parts[1])
if err != nil {
return errors.Errorf("invalid value %s for boolean key pull", parts[1])
}
t.Pull = pull
/*
** IMPORTANT: if you add more overrides here, do not forget to update README.
*/
default:
return nil, errors.Errorf("unknown key: %s", keys[1])
}
Expand Down Expand Up @@ -283,6 +299,8 @@ type Target struct {
SSH []string `json:"ssh,omitempty" hcl:"ssh,omitempty"`
Platforms []string `json:"platforms,omitempty" hcl:"platforms,omitempty"`
Outputs []string `json:"output,omitempty" hcl:"output,omitempty"`
Pull bool `json:"pull,omitempty": hcl:"pull,omitempty"`
NoCache bool `json:"no-cache,omitempty": hcl:"no-cache,omitempty"`
}

func (t *Target) normalize() {
Expand Down
4 changes: 2 additions & 2 deletions commands/build.go
Expand Up @@ -62,9 +62,9 @@ type buildOptions struct {
}

type commonOptions struct {
noCache bool
noCache *bool
progress string
pull bool
pull *bool
exportPush bool
exportLoad bool
}
Expand Down

0 comments on commit 5454b14

Please sign in to comment.