Skip to content

Commit b6bd290

Browse files
authored
Merge pull request moby#3392 from crazy-max/test-gha-cache
cache: test gha cache exporter
2 parents 71fce0a + 09b50ad commit b6bd290

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
@@ -137,6 +137,7 @@ func TestIntegration(t *testing.T) {
137137
testHostnameSpecifying,
138138
testPushByDigest,
139139
testBasicInlineCacheImportExport,
140+
testBasicGhaCacheImportExport,
140141
testExportBusyboxLocal,
141142
testBridgeNetworking,
142143
testCacheMountNoCache,
@@ -4831,6 +4832,45 @@ func testBasicInlineCacheImportExport(t *testing.T, sb integration.Sandbox) {
48314832
require.EqualValues(t, unique, unique3)
48324833
}
48334834

4835+
func testBasicGhaCacheImportExport(t *testing.T, sb integration.Sandbox) {
4836+
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport)
4837+
runtimeToken := os.Getenv("ACTIONS_RUNTIME_TOKEN")
4838+
cacheURL := os.Getenv("ACTIONS_CACHE_URL")
4839+
if runtimeToken == "" || cacheURL == "" {
4840+
t.Skip("ACTIONS_RUNTIME_TOKEN and ACTIONS_CACHE_URL must be set")
4841+
}
4842+
4843+
scope := "buildkit-" + t.Name()
4844+
if ref := os.Getenv("GITHUB_REF"); ref != "" {
4845+
if strings.HasPrefix(ref, "refs/heads/") {
4846+
scope += "-" + strings.TrimPrefix(ref, "refs/heads/")
4847+
} else if strings.HasPrefix(ref, "refs/tags/") {
4848+
scope += "-" + strings.TrimPrefix(ref, "refs/tags/")
4849+
} else if strings.HasPrefix(ref, "refs/pull/") {
4850+
scope += "-pr" + strings.TrimPrefix(strings.TrimSuffix(strings.TrimSuffix(ref, "/head"), "/merge"), "refs/pull/")
4851+
}
4852+
}
4853+
4854+
im := CacheOptionsEntry{
4855+
Type: "gha",
4856+
Attrs: map[string]string{
4857+
"url": cacheURL,
4858+
"token": runtimeToken,
4859+
"scope": scope,
4860+
},
4861+
}
4862+
ex := CacheOptionsEntry{
4863+
Type: "gha",
4864+
Attrs: map[string]string{
4865+
"url": cacheURL,
4866+
"token": runtimeToken,
4867+
"scope": scope,
4868+
"mode": "max",
4869+
},
4870+
}
4871+
testBasicCacheImportExport(t, sb, []CacheOptionsEntry{im}, []CacheOptionsEntry{ex})
4872+
}
4873+
48344874
func readFileInImage(ctx context.Context, t *testing.T, c *Client, ref, path string) ([]byte, error) {
48354875
def, err := llb.Image(ref).Marshal(ctx)
48364876
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)