Skip to content

Commit 6eaf7ab

Browse files
committed
feat: support multiple cache paths
Support multiple cache paths. Signed-off-by: Noel Georgi <[email protected]>
1 parent 6db0478 commit 6eaf7ab

File tree

7 files changed

+29
-23
lines changed

7 files changed

+29
-23
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,9 @@ steps:
196196
destination: bison.tar.xz
197197
sha256: 075cef2e814642e30e10e8155e93022e4a91ca38a65aa1d5467d4e969f97f338
198198
sha512: 00b448db8abe91b07e32ff5273c6617bc1350d806f92073a9472f4c2f0de5d22c152795674171b74f2eb9eff8d36f8173b82dacb215601bb071ae39404d4a8a2
199-
cache: "/.cache" # cache mount to be used across builds
199+
cachePaths:
200+
- /.cache/go-build
201+
- /go/pkg
200202
prepare:
201203
- tar -xJf bison.tar.xz --strip-components=1
202204
- mkdir build
@@ -320,7 +322,7 @@ Top-level keys describing phases are (all phases are optional):
320322

321323
- `sources` (download)
322324
- `env` (environment variables)
323-
- `cache` (a cache mount to be used across builds)
325+
- `cachePaths` (a list of cache mount paths to be used across builds)
324326
- `prepare` (shell script)
325327
- `build` (shell script)
326328
- `install` (shell script)

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ require (
1414
github.com/opencontainers/go-digest v1.0.0
1515
github.com/opencontainers/image-spec v1.1.0
1616
github.com/otiai10/copy v1.14.0
17+
github.com/siderolabs/gen v0.4.7
1718
github.com/spf13/cobra v1.8.0
1819
github.com/stretchr/testify v1.9.0
1920
golang.org/x/oauth2 v0.18.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
9595
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
9696
github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=
9797
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
98+
github.com/siderolabs/gen v0.4.7 h1:lM69UYggT7yzpubf7hEFaNujPdY55Y9zvQf/NC18GvA=
99+
github.com/siderolabs/gen v0.4.7/go.mod h1:4PBYMdXxTg292IDRq4CGn5AymyDxJVEDvobVKDqFBEA=
98100
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
99101
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
100102
github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=

internal/pkg/convert/node.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/moby/buildkit/client/llb"
1414
"github.com/opencontainers/go-digest"
1515
v1 "github.com/opencontainers/image-spec/specs-go/v1"
16+
"github.com/siderolabs/gen/xslices"
1617

1718
"github.com/siderolabs/bldr/internal/pkg/constants"
1819
"github.com/siderolabs/bldr/internal/pkg/environment"
@@ -270,18 +271,16 @@ func (node *NodeLLB) stepScripts(root llb.State, i int, step v1alpha2.Step) llb.
270271
for _, instruction := range script.Instructions {
271272
runOptions := append([]llb.RunOption(nil), node.Graph.commonRunOptions...)
272273

273-
if step.CachePath != "" {
274-
runOptions = append(runOptions,
275-
llb.AddMount(
276-
step.CachePath,
277-
llb.Scratch(),
278-
llb.AsPersistentCacheDir(
279-
path.Clean(node.Graph.Options.CacheIDNamespace+"/"+step.CachePath),
280-
llb.CacheMountShared,
281-
),
274+
runOptions = append(runOptions, xslices.Map(step.CachePaths, func(p string) llb.RunOption {
275+
return llb.AddMount(
276+
p,
277+
llb.Scratch(),
278+
llb.AsPersistentCacheDir(
279+
path.Clean(node.Graph.Options.CacheIDNamespace+"/"+p),
280+
llb.CacheMountShared,
282281
),
283282
)
284-
}
283+
})...)
285284

286285
runOptions = append(runOptions,
287286
llb.Args([]string{

internal/pkg/integration/testdata/cache/check-cache/pkg.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ name: check-cache
22
dependencies:
33
- stage: fill-cache
44
steps:
5-
- cache: /.cache
6-
prepare:
5+
- cachePaths:
6+
- /.cache
7+
test:
78
- "[ -e /.cache/foo ]"
89
finalize:
910
- from: /pkg

internal/pkg/integration/testdata/cache/fill-cache/pkg.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: fill-cache
22
steps:
3-
- cache: /.cache
3+
- cachePaths:
4+
- /.cache
45
prepare:
56
- echo "foo" > /.cache/foo
67

internal/pkg/types/v1alpha2/steps.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ func (steps Steps) Validate() error {
2828
// Steps are executed sequentially, each step runs in its own
2929
// empty temporary directory.
3030
type Step struct {
31-
Env Environment `yaml:"env,omitempty"`
32-
CachePath string `yaml:"cache,omitempty"`
33-
TmpDir string `yaml:"-"`
34-
Sources Sources `yaml:"sources,omitempty"`
35-
Prepare Instructions `yaml:"prepare,omitempty"`
36-
Build Instructions `yaml:"build,omitempty"`
37-
Install Instructions `yaml:"install,omitempty"`
38-
Test Instructions `yaml:"test,omitempty"`
31+
Env Environment `yaml:"env,omitempty"`
32+
CachePaths []string `yaml:"cachePaths,omitempty"`
33+
TmpDir string `yaml:"-"`
34+
Sources Sources `yaml:"sources,omitempty"`
35+
Prepare Instructions `yaml:"prepare,omitempty"`
36+
Build Instructions `yaml:"build,omitempty"`
37+
Install Instructions `yaml:"install,omitempty"`
38+
Test Instructions `yaml:"test,omitempty"`
3939
}
4040

4141
// Validate the step.

0 commit comments

Comments
 (0)