Skip to content

Commit 97650b2

Browse files
committed
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 <[email protected]>
1 parent bc2438e commit 97650b2

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

internal/pkg/convert/node.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ func (node *NodeLLB) stepScripts(root llb.State, i int, step v1alpha2.Step) llb.
265265
llb.WithCustomName(fmt.Sprintf("%s%s-%d", node.Prefix, script.Desc, i)),
266266
)
267267

268+
if node.Graph.Options.NoCache {
269+
runOptions = append(runOptions, llb.IgnoreCache)
270+
}
271+
268272
root = root.Run(runOptions...).Root()
269273
}
270274
}

internal/pkg/environment/options.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type Options struct {
2121
ProxyEnv *llb.ProxyEnv
2222
SourceDateEpoch time.Time
2323
CacheIDNamespace string
24+
NoCache bool
2425
}
2526

2627
// GetVariables returns set of variables set for options.

internal/pkg/pkgfile/build.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const (
3030
keyTarget = "target"
3131
keyTargetPlatform = "platform"
3232
keyMultiPlatform = "multi-platform"
33+
keyNoCache = "no-cache"
3334

3435
buildArgPrefix = "build-arg:"
3536
buildArgSourceDateEpoch = buildArgPrefix + "SOURCE_DATE_EPOCH"
@@ -47,6 +48,7 @@ func Build(ctx context.Context, c client.Client, options *environment.Options) (
4748

4849
options.Target = opts[keyTarget]
4950
options.ProxyEnv = proxyEnvFromBuildArgs(filter(opts, buildArgPrefix))
51+
_, options.NoCache = opts[keyNoCache]
5052

5153
if sourceDateEpoch, ok := opts[buildArgSourceDateEpoch]; ok {
5254
timestamp, err := strconv.ParseInt(sourceDateEpoch, 10, 64)

0 commit comments

Comments
 (0)