Skip to content

Commit 66e9bf2

Browse files
committed
BLO-4373 Check for matching runner and target architecture
1 parent e1ae7eb commit 66e9bf2

2 files changed

Lines changed: 29 additions & 7 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ jobs:
121121
| `docker-build-secrets` | List of secrets to expose to the build (e.g., key=string, GIT_AUTH_TOKEN=mytoken) | |
122122
| `docker-build-secret-files` | List of secret files to expose to the build (e.g., key=filename, MY_SECRET=./secret.txt) | |
123123
| `docker-build-target` | Sets the target stage to build like: "runtime" | |
124-
| `docker-build-platforms` | Sets the target platforms for build | linux/amd64,linux/arm64 |
124+
| `docker-build-platforms` | Sets the target platforms for build | linux/amd64 |
125125
| `docker-build-provenance` | Generate [provenance](https://docs.docker.com/build/attestations/slsa-provenance/) attestation for the build | `false` |
126126
| `docker-disable-retagging` | Disables retagging of existing images and run a new build instead | `false` |
127127
| `gitops-organization` | GitHub Organization for GitOps | `Staffbase` |

action.yml

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ inputs:
4242
docker-build-platforms:
4343
description: "Sets the target platforms for build"
4444
required: false
45-
default: 'linux/amd64,linux/arm64'
45+
default: 'linux/amd64'
4646
docker-build-provenance:
4747
description: "Generate provenance attestation for the build"
4848
required: false
@@ -155,11 +155,33 @@ runs:
155155
echo "tag=$TAG" >> $GITHUB_OUTPUT
156156
echo "tag_list=$TAG_LIST" >> $GITHUB_OUTPUT
157157
158-
- name: Set up QEMU
159-
if: inputs.docker-username != '' && inputs.docker-password != ''
160-
uses: docker/setup-qemu-action@v3
161-
with:
162-
platforms: arm64,amd64
158+
- name: Verify Architecture Match
159+
shell: bash
160+
if: steps.preparation.outputs.build == 'true'
161+
run: |
162+
RUNNER_ARCH="${{ runner.arch }}" # X64 (AMD64) or ARM64
163+
TARGET_PLATFORMS="${{ inputs.docker-build-platforms }}"
164+
165+
echo "Runner CPU Architecture: $RUNNER_ARCH"
166+
echo "Requested Build Platforms: $TARGET_PLATFORMS"
167+
168+
# Check for AMD64 mismatch (Runner is X64, but user requests ONLY arm64, OR user requests multi-arch which requires emulation)
169+
if [[ "$RUNNER_ARCH" == "X64" ]]; then
170+
if [[ "$TARGET_PLATFORMS" == *"linux/arm64"* ]]; then
171+
echo "::error::Runner is X64 (Intel/AMD) but build includes 'linux/arm64'. This requires emulation. Aborting strictly."
172+
exit 1
173+
fi
174+
fi
175+
176+
# Check for ARM64 mismatch
177+
if [[ "$RUNNER_ARCH" == "ARM64" ]]; then
178+
if [[ "$TARGET_PLATFORMS" == *"linux/amd64"* ]]; then
179+
echo "::error::Runner is ARM64 (Apple Silicon/Graviton) but build includes 'linux/amd64'. This requires emulation. Aborting strictly."
180+
exit 1
181+
fi
182+
fi
183+
184+
echo "Architecture match verified for native build ✅"
163185
164186
- name: Set up Docker Buildx
165187
if: inputs.docker-username != '' && inputs.docker-password != ''

0 commit comments

Comments
 (0)