build: add no-cache-filter

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
pull/860/head
Tonis Tiigi 3 years ago
parent e60f0f2c4f
commit 3b47722032

@ -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"] = ""
} }

@ -42,25 +42,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
} }
@ -116,17 +117,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)
@ -363,6 +365,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")

@ -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…
Cancel
Save