@@ -176,33 +176,47 @@ jobs:
176176 username : ${{ github.actor }}
177177 password : ${{ secrets.GITHUB_TOKEN }}
178178
179+ - name : Determine parent sandbox
180+ id : parent
181+ run : |
182+ set -euo pipefail
183+ DOCKERFILE="sandboxes/${{ matrix.sandbox }}/Dockerfile"
184+ DEFAULT_BASE=""
185+ if grep -q '^ARG BASE_IMAGE=' "$DOCKERFILE"; then
186+ DEFAULT_BASE=$(grep '^ARG BASE_IMAGE=' "$DOCKERFILE" | head -1 | cut -d= -f2-)
187+ fi
188+
189+ PARENT=""
190+ if [ -n "$DEFAULT_BASE" ]; then
191+ PARENT=$(echo "$DEFAULT_BASE" | sed -n 's|.*/sandboxes/\([^:]*\).*|\1|p')
192+ if [ -z "$PARENT" ]; then
193+ PARENT="base"
194+ fi
195+ fi
196+
197+ echo "sandbox=$PARENT" >> "$GITHUB_OUTPUT"
198+ if [ -n "$PARENT" ]; then
199+ echo "Parent for ${{ matrix.sandbox }}: $PARENT"
200+ else
201+ echo "${{ matrix.sandbox }} is a standalone sandbox image"
202+ fi
203+
179204 # 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.
205+ # local registry, and override BASE_IMAGE to point there for dependent
206+ # sandbox images. Standalone images do not need this step.
181207 - name : Build base image locally (PR only)
182- if : github.ref != 'refs/heads/main'
208+ if : github.ref != 'refs/heads/main' && steps.parent.outputs.sandbox != ''
183209 uses : docker/build-push-action@v6
184210 with :
185211 context : sandboxes/base
186212 push : true
187213 tags : localhost:5000/sandboxes/base:latest
188214 cache-from : type=gha,scope=base
189215
190- - name : Determine parent sandbox
191- id : parent
192- run : |
193- set -euo pipefail
194- DEFAULT_BASE=$(grep '^ARG BASE_IMAGE=' "sandboxes/${{ matrix.sandbox }}/Dockerfile" | head -1 | cut -d= -f2-)
195- PARENT=$(echo "$DEFAULT_BASE" | sed -n 's|.*/sandboxes/\([^:]*\).*|\1|p')
196- if [ -z "$PARENT" ]; then
197- PARENT="base"
198- fi
199- echo "sandbox=$PARENT" >> "$GITHUB_OUTPUT"
200- echo "Parent for ${{ matrix.sandbox }}: $PARENT"
201-
202216 # When a sandbox depends on another sandbox (not base), build that
203217 # intermediate parent locally so it is available to the buildx build.
204218 - name : Build parent sandbox locally (PR only)
205- if : github.ref != 'refs/heads/main' && steps.parent.outputs.sandbox != 'base'
219+ if : github.ref != 'refs/heads/main' && steps.parent.outputs.sandbox != '' && steps.parent.outputs.sandbox != ' base'
206220 uses : docker/build-push-action@v6
207221 with :
208222 context : sandboxes/${{ steps.parent.outputs.sandbox }}
@@ -216,7 +230,9 @@ jobs:
216230 id : base
217231 run : |
218232 PARENT="${{ steps.parent.outputs.sandbox }}"
219- if [ "${{ github.ref }}" = "refs/heads/main" ]; then
233+ if [ -z "$PARENT" ]; then
234+ echo "image=" >> "$GITHUB_OUTPUT"
235+ elif [ "${{ github.ref }}" = "refs/heads/main" ]; then
220236 echo "image=${{ env.REGISTRY }}/${{ steps.repo.outputs.image_prefix }}/sandboxes/${PARENT}:latest" >> "$GITHUB_OUTPUT"
221237 else
222238 echo "image=localhost:5000/sandboxes/${PARENT}:latest" >> "$GITHUB_OUTPUT"
@@ -231,11 +247,20 @@ jobs:
231247 type=sha,prefix=
232248 type=raw,value=latest,enable={{is_default_branch}}
233249
250+ - name : Set build platforms
251+ id : platforms
252+ run : |
253+ if [ "${{ github.ref }}" = "refs/heads/main" ] || [ "${{ matrix.sandbox }}" = "nvidia-gpu" ]; then
254+ echo "value=linux/amd64,linux/arm64" >> "$GITHUB_OUTPUT"
255+ else
256+ echo "value=linux/amd64" >> "$GITHUB_OUTPUT"
257+ fi
258+
234259 - name : Build and push
235260 uses : docker/build-push-action@v6
236261 with :
237262 context : sandboxes/${{ matrix.sandbox }}
238- platforms : ${{ github.ref == 'refs/heads/main' && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
263+ platforms : ${{ steps.platforms.outputs.value }}
239264 push : ${{ github.ref == 'refs/heads/main' }}
240265 tags : ${{ steps.meta.outputs.tags }}
241266 labels : ${{ steps.meta.outputs.labels }}
@@ -244,4 +269,3 @@ jobs:
244269 cache-from : type=gha,scope=${{ matrix.sandbox }}
245270 cache-to : type=gha,mode=max,scope=${{ matrix.sandbox }}
246271
247-
0 commit comments