Skip to content

Commit 8397d0b

Browse files
authored
Merge pull request moby#5004 from crazy-max/ci-gha-rest
ci: set gha cache repository and token
2 parents 1ebbf43 + 9382387 commit 8397d0b

File tree

7 files changed

+47
-4
lines changed

7 files changed

+47
-4
lines changed

.github/workflows/.test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ jobs:
9494
targets: integration-tests-base
9595
set: |
9696
*.cache-from=type=gha,scope=${{ inputs.cache_scope }}
97-
*.cache-to=type=gha,scope=${{ inputs.cache_scope }}
97+
*.cache-to=type=gha,scope=${{ inputs.cache_scope }},repository=${{ github.repository }},ghtoken=${{ secrets.GITHUB_TOKEN }}
9898
9999
run:
100100
runs-on: ubuntu-24.04

.github/workflows/buildkit.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ jobs:
106106
PLATFORMS: ${{ matrix.platform }}
107107
CACHE_FROM: type=gha,scope=binaries-${{ env.PLATFORM_PAIR }}
108108
CACHE_TO: type=gha,scope=binaries-${{ env.PLATFORM_PAIR }}
109+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
109110
-
110111
name: Upload artifacts
111112
uses: actions/upload-artifact@v4
@@ -186,6 +187,7 @@ jobs:
186187
TARGET: ${{ matrix.target-stage }}
187188
CACHE_FROM: type=gha,scope=image${{ matrix.target-stage }}
188189
CACHE_TO: type=gha,scope=image${{ matrix.target-stage }}
190+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
189191

190192
release:
191193
runs-on: ubuntu-24.04

.github/workflows/frontend.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ jobs:
123123
RELEASE: ${{ startsWith(github.ref, 'refs/tags/v') }}
124124
CACHE_FROM: type=gha,scope=${{ env.CACHE_SCOPE }}
125125
CACHE_TO: type=gha,scope=${{ env.CACHE_SCOPE }}
126+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
126127

127128
release:
128129
runs-on: ubuntu-24.04

.github/workflows/test-os.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ on:
2020

2121
env:
2222
GO_VERSION: "1.22"
23+
SETUP_BUILDX_VERSION: "latest"
24+
SETUP_BUILDKIT_IMAGE: "moby/buildkit:latest"
2325
DESTDIR: "./bin"
2426

2527
jobs:
@@ -43,6 +45,10 @@ jobs:
4345
-
4446
name: Set up Docker Buildx
4547
uses: docker/setup-buildx-action@v3
48+
with:
49+
version: ${{ env.SETUP_BUILDX_VERSION }}
50+
driver-opts: image=${{ env.SETUP_BUILDKIT_IMAGE }}
51+
buildkitd-flags: --debug
4652
-
4753
name: Build
4854
uses: docker/bake-action@v5
@@ -52,7 +58,7 @@ jobs:
5258
set: |
5359
*.platform=${{ matrix.platform }}
5460
*.cache-from=type=gha,scope=binaries-for-test-${{ env.PLATFORM_PAIR }}
55-
*.cache-to=type=gha,scope=binaries-for-test-${{ env.PLATFORM_PAIR }}
61+
*.cache-to=type=gha,scope=binaries-for-test-${{ env.PLATFORM_PAIR }},repository=${{ github.repository }},ghtoken=${{ secrets.GITHUB_TOKEN }}
5662
-
5763
name: List artifacts
5864
run: |

hack/images

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ exportCacheFlags=""
8585
if [ -n "$cacheToFlags" ]; then
8686
exportCacheFlags="$cacheToFlags"
8787
elif [ "$PUSH" = "push" ]; then
88-
exportCacheFlags="$exportCacheFlags--cache-to=type=inline "
88+
exportCacheFlags="--cache-to=type=inline"
8989
fi
9090

9191
tagFlags=""

hack/release

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ set -eu -o pipefail
55
: "${GITHUB_ACTIONS=}"
66
: "${GITHUB_REPOSITORY=}"
77
: "${GITHUB_RUN_ID=}"
8+
: "${GITHUB_TOKEN=}"
89

910
: "${BUILDX_CMD=docker buildx}"
1011
: "${DESTDIR=./bin/release}"
@@ -15,11 +16,27 @@ set -eu -o pipefail
1516

1617
if [ -n "$CACHE_FROM" ]; then
1718
for cfrom in $CACHE_FROM; do
19+
if [[ $cfrom == *"type=gha"* ]]; then
20+
if [[ -n "$GITHUB_REPOSITORY" ]] && [[ $cfrom != *"repository="* ]]; then
21+
cfrom="${cfrom},repository=${GITHUB_REPOSITORY}"
22+
fi
23+
if [[ -n "$GITHUB_TOKEN" ]] && [[ $cfrom != *"ghtoken="* ]]; then
24+
cfrom="${cfrom},ghtoken=${GITHUB_TOKEN}"
25+
fi
26+
fi
1827
setFlags+=(--set "*.cache-from=$cfrom")
1928
done
2029
fi
2130
if [ -n "$CACHE_TO" ]; then
2231
for cto in $CACHE_TO; do
32+
if [[ $cto == *"type=gha"* ]]; then
33+
if [[ -n "$GITHUB_REPOSITORY" ]] && [[ $cto != *"repository="* ]]; then
34+
cto="${cto},repository=${GITHUB_REPOSITORY}"
35+
fi
36+
if [[ -n "$GITHUB_TOKEN" ]] && [[ $cto != *"ghtoken="* ]]; then
37+
cto="${cto},ghtoken=${GITHUB_TOKEN}"
38+
fi
39+
fi
2340
setFlags+=(--set "*.cache-to=$cto")
2441
done
2542
fi

hack/util

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
#!/usr/bin/env sh
1+
#!/usr/bin/env bash
22

33
: "${BUILDX_CMD=docker buildx}"
44
: "${BUILDX_BUILDER=}"
55

66
: "${GITHUB_ACTIONS=}"
77
: "${GITHUB_REPOSITORY=}"
88
: "${GITHUB_RUN_ID=}"
9+
: "${GITHUB_TOKEN=}"
910

1011
: "${CONTEXT=}"
1112
: "${CACHE_FROM=}"
@@ -43,11 +44,27 @@ if [ "$GITHUB_ACTIONS" = "true" ] && [ "$GITHUB_REPOSITORY" = "moby/buildkit" ];
4344
currentref="https://github.com/$GITHUB_REPOSITORY.git#$GITHUB_REF"
4445
if [ -n "$CACHE_FROM" ]; then
4546
for cfrom in $CACHE_FROM; do
47+
if [[ $cfrom == *"type=gha"* ]]; then
48+
if [[ -n "$GITHUB_REPOSITORY" ]] && [[ $cfrom != *"repository="* ]]; then
49+
cfrom="${cfrom},repository=${GITHUB_REPOSITORY}"
50+
fi
51+
if [[ -n "$GITHUB_TOKEN" ]] && [[ $cfrom != *"ghtoken="* ]]; then
52+
cfrom="${cfrom},ghtoken=${GITHUB_TOKEN}"
53+
fi
54+
fi
4655
cacheFromFlags="${cacheFromFlags}--cache-from=$cfrom "
4756
done
4857
fi
4958
if [ -n "$CACHE_TO" ]; then
5059
for cto in $CACHE_TO; do
60+
if [[ $cto == *"type=gha"* ]]; then
61+
if [[ -n "$GITHUB_REPOSITORY" ]] && [[ $cto != *"repository="* ]]; then
62+
cto="${cto},repository=${GITHUB_REPOSITORY}"
63+
fi
64+
if [[ -n "$GITHUB_TOKEN" ]] && [[ $cto != *"ghtoken="* ]]; then
65+
cto="${cto},ghtoken=${GITHUB_TOKEN}"
66+
fi
67+
fi
5168
cacheToFlags="${cacheToFlags}--cache-to=$cto "
5269
done
5370
fi

0 commit comments

Comments
 (0)