mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-03 09:57:41 +08:00
Merge pull request #860 from tonistiigi/no-cache-filter
build: add no-cache-filter
This commit is contained in:
commit
eef6deb7c2
23
bake/bake.go
23
bake/bake.go
@ -524,7 +524,7 @@ type Target struct {
|
|||||||
Pull *bool `json:"pull,omitempty" hcl:"pull,optional"`
|
Pull *bool `json:"pull,omitempty" hcl:"pull,optional"`
|
||||||
NoCache *bool `json:"no-cache,omitempty" hcl:"no-cache,optional"`
|
NoCache *bool `json:"no-cache,omitempty" hcl:"no-cache,optional"`
|
||||||
NetworkMode *string `json:"-" hcl:"-"`
|
NetworkMode *string `json:"-" hcl:"-"`
|
||||||
|
NoCacheFilter []string `json:"no-cache-filter,omitempty" hcl:"no-cache-filter,optional"`
|
||||||
// IMPORTANT: if you add more fields here, do not forget to update newOverrides and README.
|
// IMPORTANT: if you add more fields here, do not forget to update newOverrides and README.
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -536,6 +536,7 @@ func (t *Target) normalize() {
|
|||||||
t.CacheFrom = removeDupes(t.CacheFrom)
|
t.CacheFrom = removeDupes(t.CacheFrom)
|
||||||
t.CacheTo = removeDupes(t.CacheTo)
|
t.CacheTo = removeDupes(t.CacheTo)
|
||||||
t.Outputs = removeDupes(t.Outputs)
|
t.Outputs = removeDupes(t.Outputs)
|
||||||
|
t.NoCacheFilter = removeDupes(t.NoCacheFilter)
|
||||||
|
|
||||||
for k, v := range t.Contexts {
|
for k, v := range t.Contexts {
|
||||||
if v == "" {
|
if v == "" {
|
||||||
@ -608,6 +609,9 @@ func (t *Target) Merge(t2 *Target) {
|
|||||||
if t2.NetworkMode != nil {
|
if t2.NetworkMode != nil {
|
||||||
t.NetworkMode = t2.NetworkMode
|
t.NetworkMode = t2.NetworkMode
|
||||||
}
|
}
|
||||||
|
if t2.NoCacheFilter != nil { // merge
|
||||||
|
t.NoCacheFilter = append(t.NoCacheFilter, t2.NoCacheFilter...)
|
||||||
|
}
|
||||||
t.Inherits = append(t.Inherits, t2.Inherits...)
|
t.Inherits = append(t.Inherits, t2.Inherits...)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -666,6 +670,8 @@ func (t *Target) AddOverrides(overrides map[string]Override) error {
|
|||||||
return errors.Errorf("invalid value %s for boolean key no-cache", value)
|
return errors.Errorf("invalid value %s for boolean key no-cache", value)
|
||||||
}
|
}
|
||||||
t.NoCache = &noCache
|
t.NoCache = &noCache
|
||||||
|
case "no-cache-filter":
|
||||||
|
t.NoCacheFilter = o.ArrValue
|
||||||
case "pull":
|
case "pull":
|
||||||
pull, err := strconv.ParseBool(value)
|
pull, err := strconv.ParseBool(value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -776,13 +782,14 @@ func toBuildOpt(t *Target, inp *Input) (*build.Options, error) {
|
|||||||
t.Context = &bi.ContextPath
|
t.Context = &bi.ContextPath
|
||||||
|
|
||||||
bo := &build.Options{
|
bo := &build.Options{
|
||||||
Inputs: bi,
|
Inputs: bi,
|
||||||
Tags: t.Tags,
|
Tags: t.Tags,
|
||||||
BuildArgs: t.Args,
|
BuildArgs: t.Args,
|
||||||
Labels: t.Labels,
|
Labels: t.Labels,
|
||||||
NoCache: noCache,
|
NoCache: noCache,
|
||||||
Pull: pull,
|
NoCacheFilter: t.NoCacheFilter,
|
||||||
NetworkMode: networkMode,
|
Pull: pull,
|
||||||
|
NetworkMode: networkMode,
|
||||||
}
|
}
|
||||||
|
|
||||||
platforms, err := platformutil.Parse(t.Platforms)
|
platforms, err := platformutil.Parse(t.Platforms)
|
||||||
|
@ -194,6 +194,14 @@ func (t *Target) composeExtTarget(exts map[string]interface{}) error {
|
|||||||
if res, ok := val.(bool); ok {
|
if res, ok := val.(bool); ok {
|
||||||
t.NoCache = &res
|
t.NoCache = &res
|
||||||
}
|
}
|
||||||
|
case "no-cache-filter":
|
||||||
|
if res, k := val.(string); k {
|
||||||
|
t.NoCacheFilter = append(t.NoCacheFilter, res)
|
||||||
|
} else {
|
||||||
|
for _, res := range val.([]interface{}) {
|
||||||
|
t.NoCacheFilter = append(t.NoCacheFilter, res.(string))
|
||||||
|
}
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("compose file invalid: unkwown %s field for x-bake", key)
|
return fmt.Errorf("compose file invalid: unkwown %s field for x-bake", key)
|
||||||
}
|
}
|
||||||
|
@ -56,24 +56,25 @@ var (
|
|||||||
type Options struct {
|
type Options struct {
|
||||||
Inputs Inputs
|
Inputs Inputs
|
||||||
|
|
||||||
Allow []entitlements.Entitlement
|
Allow []entitlements.Entitlement
|
||||||
BuildArgs map[string]string
|
BuildArgs map[string]string
|
||||||
CacheFrom []client.CacheOptionsEntry
|
CacheFrom []client.CacheOptionsEntry
|
||||||
CacheTo []client.CacheOptionsEntry
|
CacheTo []client.CacheOptionsEntry
|
||||||
CgroupParent string
|
CgroupParent string
|
||||||
Exports []client.ExportEntry
|
Exports []client.ExportEntry
|
||||||
ExtraHosts []string
|
ExtraHosts []string
|
||||||
ImageIDFile string
|
ImageIDFile string
|
||||||
Labels map[string]string
|
Labels map[string]string
|
||||||
NetworkMode string
|
NetworkMode string
|
||||||
NoCache bool
|
NoCache bool
|
||||||
Platforms []specs.Platform
|
NoCacheFilter []string
|
||||||
Pull bool
|
Platforms []specs.Platform
|
||||||
Session []session.Attachable
|
Pull bool
|
||||||
ShmSize opts.MemBytes
|
Session []session.Attachable
|
||||||
Tags []string
|
ShmSize opts.MemBytes
|
||||||
Target string
|
Tags []string
|
||||||
Ulimits *opts.UlimitOpt
|
Target string
|
||||||
|
Ulimits *opts.UlimitOpt
|
||||||
}
|
}
|
||||||
|
|
||||||
type Inputs struct {
|
type Inputs struct {
|
||||||
@ -527,6 +528,9 @@ func toSolveOpt(ctx context.Context, d driver.Driver, multiDriver bool, opt Opti
|
|||||||
if opt.Target != "" {
|
if opt.Target != "" {
|
||||||
so.FrontendAttrs["target"] = opt.Target
|
so.FrontendAttrs["target"] = opt.Target
|
||||||
}
|
}
|
||||||
|
if len(opt.NoCacheFilter) > 0 {
|
||||||
|
so.FrontendAttrs["no-cache"] = strings.Join(opt.NoCacheFilter, ",")
|
||||||
|
}
|
||||||
if opt.NoCache {
|
if opt.NoCache {
|
||||||
so.FrontendAttrs["no-cache"] = ""
|
so.FrontendAttrs["no-cache"] = ""
|
||||||
}
|
}
|
||||||
|
@ -43,25 +43,26 @@ type buildOptions struct {
|
|||||||
contextPath string
|
contextPath string
|
||||||
dockerfileName string
|
dockerfileName string
|
||||||
|
|
||||||
allow []string
|
allow []string
|
||||||
buildArgs []string
|
buildArgs []string
|
||||||
cacheFrom []string
|
cacheFrom []string
|
||||||
cacheTo []string
|
cacheTo []string
|
||||||
cgroupParent string
|
cgroupParent string
|
||||||
contexts []string
|
contexts []string
|
||||||
extraHosts []string
|
extraHosts []string
|
||||||
imageIDFile string
|
imageIDFile string
|
||||||
labels []string
|
labels []string
|
||||||
networkMode string
|
networkMode string
|
||||||
outputs []string
|
noCacheFilter []string
|
||||||
platforms []string
|
outputs []string
|
||||||
quiet bool
|
platforms []string
|
||||||
secrets []string
|
quiet bool
|
||||||
shmSize dockeropts.MemBytes
|
secrets []string
|
||||||
ssh []string
|
shmSize dockeropts.MemBytes
|
||||||
tags []string
|
ssh []string
|
||||||
target string
|
tags []string
|
||||||
ulimits *dockeropts.UlimitOpt
|
target string
|
||||||
|
ulimits *dockeropts.UlimitOpt
|
||||||
commonOptions
|
commonOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,6 +100,10 @@ func runBuild(dockerCli command.Cli, in buildOptions) (err error) {
|
|||||||
pull = *in.pull
|
pull = *in.pull
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if noCache && len(in.noCacheFilter) > 0 {
|
||||||
|
return errors.Errorf("--no-cache and --no-cache-filter cannot currently be used together")
|
||||||
|
}
|
||||||
|
|
||||||
if in.quiet && in.progress != "auto" && in.progress != "quiet" {
|
if in.quiet && in.progress != "auto" && in.progress != "quiet" {
|
||||||
return errors.Errorf("progress=%s and quiet cannot be used together", in.progress)
|
return errors.Errorf("progress=%s and quiet cannot be used together", in.progress)
|
||||||
} else if in.quiet {
|
} else if in.quiet {
|
||||||
@ -117,17 +122,18 @@ func runBuild(dockerCli command.Cli, in buildOptions) (err error) {
|
|||||||
InStream: os.Stdin,
|
InStream: os.Stdin,
|
||||||
NamedContexts: contexts,
|
NamedContexts: contexts,
|
||||||
},
|
},
|
||||||
BuildArgs: listToMap(in.buildArgs, true),
|
BuildArgs: listToMap(in.buildArgs, true),
|
||||||
ExtraHosts: in.extraHosts,
|
ExtraHosts: in.extraHosts,
|
||||||
ImageIDFile: in.imageIDFile,
|
ImageIDFile: in.imageIDFile,
|
||||||
Labels: listToMap(in.labels, false),
|
Labels: listToMap(in.labels, false),
|
||||||
NetworkMode: in.networkMode,
|
NetworkMode: in.networkMode,
|
||||||
NoCache: noCache,
|
NoCache: noCache,
|
||||||
Pull: pull,
|
NoCacheFilter: in.noCacheFilter,
|
||||||
ShmSize: in.shmSize,
|
Pull: pull,
|
||||||
Tags: in.tags,
|
ShmSize: in.shmSize,
|
||||||
Target: in.target,
|
Tags: in.tags,
|
||||||
Ulimits: in.ulimits,
|
Target: in.target,
|
||||||
|
Ulimits: in.ulimits,
|
||||||
}
|
}
|
||||||
|
|
||||||
platforms, err := platformutil.Parse(in.platforms)
|
platforms, err := platformutil.Parse(in.platforms)
|
||||||
@ -360,6 +366,8 @@ func buildCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
|
|||||||
|
|
||||||
flags.StringVar(&options.networkMode, "network", "default", `Set the networking mode for the "RUN" instructions during build`)
|
flags.StringVar(&options.networkMode, "network", "default", `Set the networking mode for the "RUN" instructions during build`)
|
||||||
|
|
||||||
|
flags.StringArrayVar(&options.noCacheFilter, "no-cache-filter", []string{}, "Do not cache specified stages")
|
||||||
|
|
||||||
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")`)
|
||||||
|
|
||||||
flags.StringArrayVar(&options.platforms, "platform", platformsDefault, "Set target platform for build")
|
flags.StringArrayVar(&options.platforms, "platform", platformsDefault, "Set target platform for build")
|
||||||
|
@ -340,7 +340,7 @@ target "db" {
|
|||||||
Complete list of valid target fields:
|
Complete list of valid target fields:
|
||||||
|
|
||||||
`args`, `cache-from`, `cache-to`, `context`, `contexts`, `dockerfile`, `inherits`, `labels`,
|
`args`, `cache-from`, `cache-to`, `context`, `contexts`, `dockerfile`, `inherits`, `labels`,
|
||||||
`no-cache`, `output`, `platform`, `pull`, `secrets`, `ssh`, `tags`, `target`
|
`no-cache`, `no-cache-filter`, `output`, `platform`, `pull`, `secrets`, `ssh`, `tags`, `target`
|
||||||
|
|
||||||
### Global scope attributes
|
### Global scope attributes
|
||||||
|
|
||||||
@ -982,7 +982,7 @@ $ docker buildx bake --print
|
|||||||
Complete list of valid fields for `x-bake`:
|
Complete list of valid fields for `x-bake`:
|
||||||
|
|
||||||
`tags`, `cache-from`, `cache-to`, `secret`, `ssh`, `platforms`, `output`,
|
`tags`, `cache-from`, `cache-to`, `secret`, `ssh`, `platforms`, `output`,
|
||||||
`pull`, `no-cache`
|
`pull`, `no-cache`, `no-cache-filter`
|
||||||
|
|
||||||
### Built-in variables
|
### Built-in variables
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@ Start a build
|
|||||||
| `--metadata-file string` | Write build result metadata to the file |
|
| `--metadata-file string` | Write build result metadata to the file |
|
||||||
| `--network string` | Set the networking mode for the `RUN` instructions during build |
|
| `--network string` | Set the networking mode for the `RUN` instructions during build |
|
||||||
| `--no-cache` | Do not use cache when building the image |
|
| `--no-cache` | Do not use cache when building the image |
|
||||||
|
| `--no-cache-filter stringArray` | Do not cache specified stages |
|
||||||
| [`-o`](#output), [`--output stringArray`](#output) | Output destination (format: `type=local,dest=path`) |
|
| [`-o`](#output), [`--output stringArray`](#output) | Output destination (format: `type=local,dest=path`) |
|
||||||
| [`--platform stringArray`](#platform) | Set target platform for build |
|
| [`--platform stringArray`](#platform) | Set target platform for build |
|
||||||
| [`--progress string`](#progress) | Set type of progress output (`auto`, `plain`, `tty`). Use plain to show container output |
|
| [`--progress string`](#progress) | Set type of progress output (`auto`, `plain`, `tty`). Use plain to show container output |
|
||||||
|
Loading…
x
Reference in New Issue
Block a user