From 3b477220323d4ded7e0c9b42bba6b6ae87a4dc7e Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Mon, 22 Nov 2021 20:21:35 -0800 Subject: [PATCH] build: add no-cache-filter Signed-off-by: Tonis Tiigi --- build/build.go | 40 +++++++++++---------- commands/build.go | 64 ++++++++++++++++++---------------- docs/reference/buildx_build.md | 1 + 3 files changed, 57 insertions(+), 48 deletions(-) diff --git a/build/build.go b/build/build.go index 2c9c07e0..9dcecb58 100644 --- a/build/build.go +++ b/build/build.go @@ -56,24 +56,25 @@ var ( type Options struct { Inputs Inputs - Allow []entitlements.Entitlement - BuildArgs map[string]string - CacheFrom []client.CacheOptionsEntry - CacheTo []client.CacheOptionsEntry - CgroupParent string - Exports []client.ExportEntry - ExtraHosts []string - ImageIDFile string - Labels map[string]string - NetworkMode string - NoCache bool - Platforms []specs.Platform - Pull bool - Session []session.Attachable - ShmSize opts.MemBytes - Tags []string - Target string - Ulimits *opts.UlimitOpt + Allow []entitlements.Entitlement + BuildArgs map[string]string + CacheFrom []client.CacheOptionsEntry + CacheTo []client.CacheOptionsEntry + CgroupParent string + Exports []client.ExportEntry + ExtraHosts []string + ImageIDFile string + Labels map[string]string + NetworkMode string + NoCache bool + NoCacheFilter []string + Platforms []specs.Platform + Pull bool + Session []session.Attachable + ShmSize opts.MemBytes + Tags []string + Target string + Ulimits *opts.UlimitOpt } type Inputs struct { @@ -527,6 +528,9 @@ func toSolveOpt(ctx context.Context, d driver.Driver, multiDriver bool, opt Opti if opt.Target != "" { so.FrontendAttrs["target"] = opt.Target } + if len(opt.NoCacheFilter) > 0 { + so.FrontendAttrs["no-cache"] = strings.Join(opt.NoCacheFilter, ",") + } if opt.NoCache { so.FrontendAttrs["no-cache"] = "" } diff --git a/commands/build.go b/commands/build.go index 2e66c583..97c18799 100644 --- a/commands/build.go +++ b/commands/build.go @@ -42,25 +42,26 @@ type buildOptions struct { contextPath string dockerfileName string - allow []string - buildArgs []string - cacheFrom []string - cacheTo []string - cgroupParent string - contexts []string - extraHosts []string - imageIDFile string - labels []string - networkMode string - outputs []string - platforms []string - quiet bool - secrets []string - shmSize dockeropts.MemBytes - ssh []string - tags []string - target string - ulimits *dockeropts.UlimitOpt + allow []string + buildArgs []string + cacheFrom []string + cacheTo []string + cgroupParent string + contexts []string + extraHosts []string + imageIDFile string + labels []string + networkMode string + noCacheFilter []string + outputs []string + platforms []string + quiet bool + secrets []string + shmSize dockeropts.MemBytes + ssh []string + tags []string + target string + ulimits *dockeropts.UlimitOpt commonOptions } @@ -116,17 +117,18 @@ func runBuild(dockerCli command.Cli, in buildOptions) (err error) { InStream: os.Stdin, NamedContexts: contexts, }, - BuildArgs: listToMap(in.buildArgs, true), - ExtraHosts: in.extraHosts, - ImageIDFile: in.imageIDFile, - Labels: listToMap(in.labels, false), - NetworkMode: in.networkMode, - NoCache: noCache, - Pull: pull, - ShmSize: in.shmSize, - Tags: in.tags, - Target: in.target, - Ulimits: in.ulimits, + BuildArgs: listToMap(in.buildArgs, true), + ExtraHosts: in.extraHosts, + ImageIDFile: in.imageIDFile, + Labels: listToMap(in.labels, false), + NetworkMode: in.networkMode, + NoCache: noCache, + NoCacheFilter: in.noCacheFilter, + Pull: pull, + ShmSize: in.shmSize, + Tags: in.tags, + Target: in.target, + Ulimits: in.ulimits, } 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.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.StringArrayVar(&options.platforms, "platform", platformsDefault, "Set target platform for build") diff --git a/docs/reference/buildx_build.md b/docs/reference/buildx_build.md index 2d415394..39ac9ac9 100644 --- a/docs/reference/buildx_build.md +++ b/docs/reference/buildx_build.md @@ -30,6 +30,7 @@ Start a build | `--metadata-file string` | Write build result metadata to the file | | `--network string` | Set the networking mode for the `RUN` instructions during build | | `--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`) | | [`--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 |