Skip to content

Commit 87a8d20

Browse files
Fix Docker cache layer compatibility (#178)
* Fix Docker cache architecture mismatch in PR workflow Add explicit single-arch platform declaration and update cache scopes to use -amd64 suffix. This ensures PR builds can reuse cache from release workflow's single-arch build step. Changes: - Add platforms: linux/amd64 to build-push-action - Update cache-from scopes: pr-{number}-amd64, release-amd64 - Update cache-to scope: pr-{number}-amd64 This resolves the 0 CACHED steps issue where single-arch PR builds could not reuse multi-arch release cache layers. * Add single-arch cache build to release workflow Add dedicated single-arch (amd64) cache build step before multi-arch builds to enable PR workflows to reuse release cache. Both beta and stable release jobs now use two-step pattern: 1. Build single-arch for cache (push: false) 2. Build multi-arch for publishing (push: true) Changes: - Add single-arch cache step to publish-prerelease job - Add single-arch cache step to publish-release job - Update both multi-arch steps to import from release-amd64 cache This enables cache cross-pollination: release builds populate release-amd64 cache, which PR builds can then reuse. * Update pkg-pr-new workflow to use single-arch caches Add single-arch cache fallbacks to preview builds to enable reuse of PR and release single-arch caches. Multi-arch preview builds can now import layers from: 1. Own preview cache (warm subsequent builds) 2. PR single-arch cache (reuse from pullrequest.yml) 3. Release single-arch cache (reuse from release.yml) 4. Release multi-arch cache (fallback) This reduces cold cache build times for preview packages from 10+ min to 2-3 min after first PR build completes.
1 parent b0c4c97 commit 87a8d20

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

.github/workflows/pkg-pr-new.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ jobs:
8282
tags: cloudflare/sandbox:${{ steps.package-version.outputs.version }}
8383
cache-from: |
8484
type=gha,scope=preview-pr-${{ github.event.pull_request.number }}
85-
type=gha,scope=pr-${{ github.event.pull_request.number }}
85+
type=gha,scope=pr-${{ github.event.pull_request.number }}-amd64
86+
type=gha,scope=release-amd64
8687
type=gha,scope=release
8788
cache-to: type=gha,mode=max,scope=preview-pr-${{ github.event.pull_request.number }}
8889
build-args: |

.github/workflows/pullrequest.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,13 @@ jobs:
120120
with:
121121
context: .
122122
file: packages/sandbox/Dockerfile
123+
platforms: linux/amd64 # Explicit single-arch for compatibility with release-amd64 cache
123124
load: true # Load into Docker daemon for local testing
124125
tags: cloudflare/sandbox-test:${{ needs.unit-tests.outputs.version || '0.0.0' }}
125126
cache-from: |
126-
type=gha,scope=pr-${{ github.event.pull_request.number }}
127-
type=gha,scope=release
128-
cache-to: type=gha,mode=max,scope=pr-${{ github.event.pull_request.number }}
127+
type=gha,scope=pr-${{ github.event.pull_request.number }}-amd64
128+
type=gha,scope=release-amd64
129+
cache-to: type=gha,mode=max,scope=pr-${{ github.event.pull_request.number }}-amd64
129130
build-args: |
130131
SANDBOX_VERSION=${{ needs.unit-tests.outputs.version || '0.0.0' }}
131132

.github/workflows/release.yml

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,18 @@ jobs:
113113
username: ${{ secrets.DOCKER_HUB_USERNAME }}
114114
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
115115

116+
- name: Build and cache single-arch image (for PR cache reuse)
117+
uses: docker/build-push-action@v6
118+
with:
119+
context: .
120+
file: packages/sandbox/Dockerfile
121+
platforms: linux/amd64
122+
push: false # Don't push, just cache
123+
cache-from: type=gha,scope=release-amd64
124+
cache-to: type=gha,mode=max,scope=release-amd64
125+
build-args: |
126+
SANDBOX_VERSION=${{ needs.unit-tests.outputs.version }}
127+
116128
- name: Build and push Docker image (beta)
117129
uses: docker/build-push-action@v6
118130
with:
@@ -121,7 +133,9 @@ jobs:
121133
platforms: linux/amd64,linux/arm64
122134
push: true
123135
tags: cloudflare/sandbox:${{ needs.unit-tests.outputs.version }}-beta
124-
cache-from: type=gha,scope=release
136+
cache-from: |
137+
type=gha,scope=release-amd64
138+
type=gha,scope=release
125139
cache-to: type=gha,mode=max,scope=release
126140
build-args: |
127141
SANDBOX_VERSION=${{ needs.unit-tests.outputs.version }}
@@ -170,6 +184,18 @@ jobs:
170184
username: ${{ secrets.DOCKER_HUB_USERNAME }}
171185
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
172186

187+
- name: Build and cache single-arch image (for PR cache reuse)
188+
uses: docker/build-push-action@v6
189+
with:
190+
context: .
191+
file: packages/sandbox/Dockerfile
192+
platforms: linux/amd64
193+
push: false # Don't push, just cache
194+
cache-from: type=gha,scope=release-amd64
195+
cache-to: type=gha,mode=max,scope=release-amd64
196+
build-args: |
197+
SANDBOX_VERSION=${{ needs.unit-tests.outputs.version }}
198+
173199
- name: Build and push Docker image
174200
uses: docker/build-push-action@v6
175201
with:
@@ -178,7 +204,9 @@ jobs:
178204
platforms: linux/amd64,linux/arm64
179205
push: true
180206
tags: cloudflare/sandbox:${{ needs.unit-tests.outputs.version }}
181-
cache-from: type=gha,scope=release
207+
cache-from: |
208+
type=gha,scope=release-amd64
209+
type=gha,scope=release
182210
cache-to: type=gha,mode=max,scope=release
183211
build-args: |
184212
SANDBOX_VERSION=${{ needs.unit-tests.outputs.version }}

0 commit comments

Comments
 (0)