Skip to content

Commit 09b50ad

Browse files
committed
cache: test gha cache exporter
Signed-off-by: CrazyMax <[email protected]>
1 parent 01c0d67 commit 09b50ad

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

client/client_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ func TestIntegration(t *testing.T) {
133133
testHostnameSpecifying,
134134
testPushByDigest,
135135
testBasicInlineCacheImportExport,
136+
testBasicGhaCacheImportExport,
136137
testExportBusyboxLocal,
137138
testBridgeNetworking,
138139
testCacheMountNoCache,
@@ -4723,6 +4724,45 @@ func testBasicInlineCacheImportExport(t *testing.T, sb integration.Sandbox) {
47234724
require.EqualValues(t, unique, unique3)
47244725
}
47254726

4727+
func testBasicGhaCacheImportExport(t *testing.T, sb integration.Sandbox) {
4728+
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport)
4729+
runtimeToken := os.Getenv("ACTIONS_RUNTIME_TOKEN")
4730+
cacheURL := os.Getenv("ACTIONS_CACHE_URL")
4731+
if runtimeToken == "" || cacheURL == "" {
4732+
t.Skip("ACTIONS_RUNTIME_TOKEN and ACTIONS_CACHE_URL must be set")
4733+
}
4734+
4735+
scope := "buildkit-" + t.Name()
4736+
if ref := os.Getenv("GITHUB_REF"); ref != "" {
4737+
if strings.HasPrefix(ref, "refs/heads/") {
4738+
scope += "-" + strings.TrimPrefix(ref, "refs/heads/")
4739+
} else if strings.HasPrefix(ref, "refs/tags/") {
4740+
scope += "-" + strings.TrimPrefix(ref, "refs/tags/")
4741+
} else if strings.HasPrefix(ref, "refs/pull/") {
4742+
scope += "-pr" + strings.TrimPrefix(strings.TrimSuffix(strings.TrimSuffix(ref, "/head"), "/merge"), "refs/pull/")
4743+
}
4744+
}
4745+
4746+
im := CacheOptionsEntry{
4747+
Type: "gha",
4748+
Attrs: map[string]string{
4749+
"url": cacheURL,
4750+
"token": runtimeToken,
4751+
"scope": scope,
4752+
},
4753+
}
4754+
ex := CacheOptionsEntry{
4755+
Type: "gha",
4756+
Attrs: map[string]string{
4757+
"url": cacheURL,
4758+
"token": runtimeToken,
4759+
"scope": scope,
4760+
"mode": "max",
4761+
},
4762+
}
4763+
testBasicCacheImportExport(t, sb, []CacheOptionsEntry{im}, []CacheOptionsEntry{ex})
4764+
}
4765+
47264766
func readFileInImage(ctx context.Context, t *testing.T, c *Client, ref, path string) ([]byte, error) {
47274767
def, err := llb.Image(ref).Marshal(ctx)
47284768
if err != nil {

hack/test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ if ! docker container inspect "$cacheVolume" >/dev/null 2>/dev/null; then
7272
fi
7373

7474
if [ "$TEST_INTEGRATION" == 1 ]; then
75-
cid=$(docker create --rm -v /tmp $coverageVol --volumes-from=$cacheVolume -e TEST_DOCKERD -e SKIP_INTEGRATION_TESTS ${BUILDKIT_INTEGRATION_SNAPSHOTTER:+"-eBUILDKIT_INTEGRATION_SNAPSHOTTER"} -e BUILDKIT_REGISTRY_MIRROR_DIR=/root/.cache/registry --privileged $iid go test $coverageFlags ${TESTFLAGS:--v} ${TESTPKGS:-./...})
75+
cid=$(docker create --rm -v /tmp $coverageVol --volumes-from=$cacheVolume -e GITHUB_REF -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e TEST_DOCKERD -e SKIP_INTEGRATION_TESTS ${BUILDKIT_INTEGRATION_SNAPSHOTTER:+"-eBUILDKIT_INTEGRATION_SNAPSHOTTER"} -e BUILDKIT_REGISTRY_MIRROR_DIR=/root/.cache/registry --privileged $iid go test $coverageFlags ${TESTFLAGS:--v} ${TESTPKGS:-./...})
7676
if [ "$TEST_DOCKERD" = "1" ]; then
7777
docker cp "$TEST_DOCKERD_BINARY" $cid:/usr/bin/dockerd
7878
fi
@@ -112,7 +112,7 @@ if [ "$TEST_DOCKERFILE" == 1 ]; then
112112

113113
if [ -s $tarout ]; then
114114
if [ "$release" = "mainline" ] || [ "$release" = "labs" ] || [ -n "$DOCKERFILE_RELEASES_CUSTOM" ] || [ "$GITHUB_ACTIONS" = "true" ]; then
115-
cid=$(docker create -v /tmp $coverageVol --rm --privileged --volumes-from=$cacheVolume -e TEST_DOCKERD -e BUILDKIT_REGISTRY_MIRROR_DIR=/root/.cache/registry -e BUILDKIT_WORKER_RANDOM -e FRONTEND_GATEWAY_ONLY=local:/$release.tar -e EXTERNAL_DF_FRONTEND=/dockerfile-frontend $iid go test $coverageFlags --count=1 -tags "$buildtags" ${TESTFLAGS:--v} ./frontend/dockerfile)
115+
cid=$(docker create -v /tmp $coverageVol --rm --privileged --volumes-from=$cacheVolume -e GITHUB_REF -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e TEST_DOCKERD -e BUILDKIT_REGISTRY_MIRROR_DIR=/root/.cache/registry -e BUILDKIT_WORKER_RANDOM -e FRONTEND_GATEWAY_ONLY=local:/$release.tar -e EXTERNAL_DF_FRONTEND=/dockerfile-frontend $iid go test $coverageFlags --count=1 -tags "$buildtags" ${TESTFLAGS:--v} ./frontend/dockerfile)
116116
docker cp $tarout $cid:/$release.tar
117117
if [ "$TEST_DOCKERD" = "1" ]; then
118118
docker cp "$TEST_DOCKERD_BINARY" $cid:/usr/bin/dockerd

0 commit comments

Comments
 (0)