Skip to content

Commit 332b592

Browse files
committed
Fix PR builds: use local registry for base image in dependent sandbox builds
On PRs the base image is not pushed to GHCR, so dependent sandbox builds cannot resolve the FROM reference. This spins up a local registry on PRs, builds the base image into it, and points BASE_IMAGE there. On main the existing GHCR flow is unchanged. PR builds also use single-platform (linux/amd64) for speed since they only validate the build.
1 parent f08404d commit 332b592

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

.github/workflows/build-sandboxes.yml

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,17 @@ jobs:
157157
- name: Set up QEMU
158158
uses: docker/setup-qemu-action@v3
159159

160+
# On PRs, use a local registry so the base image built in this job is
161+
# accessible to the subsequent buildx build (docker-container driver
162+
# cannot see images loaded into the host daemon).
163+
- name: Start local registry (PR only)
164+
if: github.ref != 'refs/heads/main'
165+
run: docker run -d -p 5000:5000 --name registry registry:2
166+
160167
- name: Set up Docker Buildx
161168
uses: docker/setup-buildx-action@v3
169+
with:
170+
driver-opts: ${{ github.ref != 'refs/heads/main' && 'network=host' || '' }}
162171

163172
- name: Log in to GHCR
164173
uses: docker/login-action@v3
@@ -167,6 +176,26 @@ jobs:
167176
username: ${{ github.actor }}
168177
password: ${{ secrets.GITHUB_TOKEN }}
169178

179+
# On PRs the base image is not in GHCR. Build it locally, push to the
180+
# local registry, and override BASE_IMAGE to point there.
181+
- name: Build base image locally (PR only)
182+
if: github.ref != 'refs/heads/main'
183+
uses: docker/build-push-action@v6
184+
with:
185+
context: sandboxes/base
186+
push: true
187+
tags: localhost:5000/sandboxes/base:latest
188+
cache-from: type=gha,scope=base
189+
190+
- name: Set BASE_IMAGE
191+
id: base
192+
run: |
193+
if [ "${{ github.ref }}" = "refs/heads/main" ]; then
194+
echo "image=${{ env.REGISTRY }}/${{ steps.repo.outputs.image_prefix }}/sandboxes/base:latest" >> "$GITHUB_OUTPUT"
195+
else
196+
echo "image=localhost:5000/sandboxes/base:latest" >> "$GITHUB_OUTPUT"
197+
fi
198+
170199
- name: Generate image metadata
171200
id: meta
172201
uses: docker/metadata-action@v5
@@ -180,11 +209,11 @@ jobs:
180209
uses: docker/build-push-action@v6
181210
with:
182211
context: sandboxes/${{ matrix.sandbox }}
183-
platforms: linux/amd64,linux/arm64
212+
platforms: ${{ github.ref == 'refs/heads/main' && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
184213
push: ${{ github.ref == 'refs/heads/main' }}
185214
tags: ${{ steps.meta.outputs.tags }}
186215
labels: ${{ steps.meta.outputs.labels }}
187216
build-args: |
188-
BASE_IMAGE=${{ env.REGISTRY }}/${{ steps.repo.outputs.image_prefix }}/sandboxes/base:latest
217+
BASE_IMAGE=${{ steps.base.outputs.image }}
189218
cache-from: type=gha,scope=${{ matrix.sandbox }}
190219
cache-to: type=gha,mode=max,scope=${{ matrix.sandbox }}

0 commit comments

Comments
 (0)