From 97650b2f1008755eb96718b02506da6ec9a9d5da Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Thu, 18 May 2023 23:23:55 +0400 Subject: [PATCH] feat: implement --no-cache option If standard `--no-cache` option is specified, `bldr` adds option to ignore cache for all `RUN` steps: all download stages are still cached, but all prepare/build/install stages are run once again. This is very helpful for reproducibility testing. Signed-off-by: Andrey Smirnov --- internal/pkg/convert/node.go | 4 ++++ internal/pkg/environment/options.go | 1 + internal/pkg/pkgfile/build.go | 2 ++ 3 files changed, 7 insertions(+) diff --git a/internal/pkg/convert/node.go b/internal/pkg/convert/node.go index 66d2375..f91294e 100644 --- a/internal/pkg/convert/node.go +++ b/internal/pkg/convert/node.go @@ -265,6 +265,10 @@ func (node *NodeLLB) stepScripts(root llb.State, i int, step v1alpha2.Step) llb. llb.WithCustomName(fmt.Sprintf("%s%s-%d", node.Prefix, script.Desc, i)), ) + if node.Graph.Options.NoCache { + runOptions = append(runOptions, llb.IgnoreCache) + } + root = root.Run(runOptions...).Root() } } diff --git a/internal/pkg/environment/options.go b/internal/pkg/environment/options.go index e4f007c..9308aab 100644 --- a/internal/pkg/environment/options.go +++ b/internal/pkg/environment/options.go @@ -21,6 +21,7 @@ type Options struct { ProxyEnv *llb.ProxyEnv SourceDateEpoch time.Time CacheIDNamespace string + NoCache bool } // GetVariables returns set of variables set for options. diff --git a/internal/pkg/pkgfile/build.go b/internal/pkg/pkgfile/build.go index 38afd2e..dd1c5e2 100644 --- a/internal/pkg/pkgfile/build.go +++ b/internal/pkg/pkgfile/build.go @@ -30,6 +30,7 @@ const ( keyTarget = "target" keyTargetPlatform = "platform" keyMultiPlatform = "multi-platform" + keyNoCache = "no-cache" buildArgPrefix = "build-arg:" buildArgSourceDateEpoch = buildArgPrefix + "SOURCE_DATE_EPOCH" @@ -47,6 +48,7 @@ func Build(ctx context.Context, c client.Client, options *environment.Options) ( options.Target = opts[keyTarget] options.ProxyEnv = proxyEnvFromBuildArgs(filter(opts, buildArgPrefix)) + _, options.NoCache = opts[keyNoCache] if sourceDateEpoch, ok := opts[buildArgSourceDateEpoch]; ok { timestamp, err := strconv.ParseInt(sourceDateEpoch, 10, 64)