Skip to content

Commit b0a1247

Browse files
committed
feat: Passthrough for cache-{from,to} from integration tests to copa
Signed-off-by: Brian Goff <[email protected]>
1 parent 8ebd10b commit b0a1247

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

.github/workflows/build.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,13 @@ jobs:
116116
./copa --version
117117
- name: Set up QEMU
118118
uses: docker/setup-qemu-action@2b82ce82d56a2a04d2637cd93a637ae1b359c0a7 # v2.2.0
119+
- name: Setup gha cache vars
120+
uses: crazy-max/ghaction-github-runtime@v2
119121
- name: Run functional test
120122
shell: bash
121123
run: |
122124
set -eu -o pipefail
123125
. .github/workflows/scripts/buildkitenvs/${{ matrix.buildkit_mode}}
124-
go test -v ./integration --addr="${COPA_BUILDKIT_ADDR}" --copa="$(pwd)/copa"
126+
go test -v ./integration --addr="${COPA_BUILDKIT_ADDR}" --copa="$(pwd)/copa" --cache-from=type=gha,scope=${{matrix.buildkit_mode}} --cache-to=type=gha,scope=${{ matrix.buildkit_mode }}
125127
126128

integration/main_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ import (
99
var (
1010
buildkitAddr string
1111
copaPath string
12+
cacheFrom string
13+
cacheTo string
1214
)
1315

1416
func TestMain(m *testing.M) {
1517
flag.StringVar(&buildkitAddr, "addr", "", "buildkit address to pass through to copa binary")
1618
flag.StringVar(&copaPath, "copa", "./copa", "path to copa binary")
19+
flag.StringVar(&cacheFrom, "cache-from", "", "pass through cache-from to copa binary")
20+
flag.StringVar(&cacheTo, "cache-to", "", "pass through cache-to to copa binary")
1721
flag.Parse()
1822

1923
if copaPath == "" {

integration/patch_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,18 @@ func patch(t *testing.T, ref, patchedTag, scan string) {
8787
"-t="+patchedTag,
8888
"-r="+scan,
8989
"--timeout=20m",
90+
func() string {
91+
if cacheFrom == "" {
92+
return ""
93+
}
94+
return "--cache-from=" + cacheFrom
95+
}(),
96+
func() string {
97+
if cacheTo == "" {
98+
return ""
99+
}
100+
return "--cache-to=" + cacheTo
101+
}(),
90102
addrFl,
91103
)
92104
out, err := cmd.CombinedOutput()

pkg/patch/cmd.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ func NewPatchCmd() *cobra.Command {
4040
flags.StringVarP(&ua.WorkDir, "working-folder", "w", "", "Working folder, defaults to system temp folder")
4141
flags.StringVarP(&ua.BuildkitAddr, "addr", "a", "", "Address of buildkitd service, defaults to local docker daemon with fallback to "+buildkit.DefaultAddr)
4242
flags.DurationVar(&ua.Timeout, "timeout", 5*time.Minute, "Timeout for the operation, defaults to '5m'")
43-
flags.StringSliceVar(&ua.CacheFrom, "cache-from", nil, "Cache import sources")
44-
flags.StringSliceVar(&ua.CacheTo, "cache-to", nil, "Cache export destination")
43+
flags.StringArrayVar(&ua.CacheFrom, "cache-from", []string{}, "Cache import sources")
44+
flags.StringArrayVar(&ua.CacheTo, "cache-to", []string{}, "Cache export destination")
4545

4646
if err := patchCmd.MarkFlagRequired("image"); err != nil {
4747
panic(err)

0 commit comments

Comments
 (0)