Skip to content

Commit

Permalink
feat: implement --no-cache option
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
smira committed May 18, 2023
1 parent bc2438e commit 97650b2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/pkg/convert/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/environment/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions internal/pkg/pkgfile/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const (
keyTarget = "target"
keyTargetPlatform = "platform"
keyMultiPlatform = "multi-platform"
keyNoCache = "no-cache"

buildArgPrefix = "build-arg:"
buildArgSourceDateEpoch = buildArgPrefix + "SOURCE_DATE_EPOCH"
Expand All @@ -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)
Expand Down

0 comments on commit 97650b2

Please sign in to comment.