Skip to content

Commit a9283a2

Browse files
committed
ci: fix wrong-arch build from stale alpine image tag
The binfmt check pulls alpine:3.23 for both arm64 and arm/v7, leaving the single local tag pointing at the last-pulled arch. On runners using the classic docker image store, 'docker run --platform linux/arm64' then reuses that stale arm/v7 image: the aarch64 iteration silently built 32-bit binaries into out/armhf and 'cp out/aarch64/*' failed. - build-static.sh: 'docker pull --platform' before each run so the local tag matches the requested platform; pass ARCH_LABEL explicitly. - build-in-container.sh: use $ARCH_LABEL (fall back to uname only for manual runs) and assert it matches the container's uname, so a wrong-platform image fails loudly instead of mislabeling binaries. Signed-off-by: ravindu644 <droidcasts@protonmail.com>
1 parent 7c72f41 commit a9283a2

2 files changed

Lines changed: 30 additions & 9 deletions

File tree

scripts/build-in-container.sh

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,26 @@
1414
# Output -> /work/out, build scratch -> /work/.src-cache
1515
set -e
1616

17-
# Derive the arch label from the (emulated) container arch. build-static.sh runs
18-
# this once per --platform; output is kept in a per-arch subdir.
19-
case "$(uname -m)" in
20-
aarch64) ARCH_LABEL=aarch64 ;;
21-
armv7l|armv7|armhf|arm) ARCH_LABEL=armhf ;;
22-
*) echo "unsupported build arch: $(uname -m)"; exit 1 ;;
17+
# Arch label drives the per-arch output subdir. build-static.sh passes it via
18+
# $ARCH_LABEL (authoritative - it knows the requested --platform). Fall back to
19+
# `uname -m` only for standalone/manual runs; uname is unreliable under emulation.
20+
if [ -z "${ARCH_LABEL:-}" ]; then
21+
case "$(uname -m)" in
22+
aarch64) ARCH_LABEL=aarch64 ;;
23+
armv7l|armv7|armhf|arm) ARCH_LABEL=armhf ;;
24+
*) echo "unsupported build arch: $(uname -m)"; exit 1 ;;
25+
esac
26+
fi
27+
echo "### Target arch: $ARCH_LABEL (uname -m: $(uname -m))"
28+
29+
# Sanity-check: the toolchain's actual word size must match the requested arch,
30+
# so a wrong-platform container (stale image cache) fails loudly instead of
31+
# silently producing mislabeled binaries.
32+
case "$ARCH_LABEL:$(uname -m)" in
33+
aarch64:aarch64) ;;
34+
armhf:armv7l|armhf:armv7|armhf:armhf|armhf:arm) ;;
35+
*) echo "ERROR: ARCH_LABEL=$ARCH_LABEL but container is $(uname -m) - wrong-platform image?"; exit 1 ;;
2336
esac
24-
echo "### Target arch: $ARCH_LABEL ($(uname -m))"
2537

2638
OUT="/work/out/$ARCH_LABEL"
2739
SRC="/work/.src-cache/$ARCH_LABEL"

scripts/build-static.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,18 @@ fi
3737
for pair in $ARCHES; do
3838
label="${pair%%:*}"; platform="${pair##*:}"
3939
echo "[*] Building $label ($platform) in $IMAGE ..."
40-
# :z relabels the bind mount for SELinux (Fedora/RHEL hosts). externals/ is
41-
# mounted read-only; the container copies sources out before building.
40+
# Pull the image for THIS platform right before running. alpine:3.23 is a
41+
# single local tag, so the earlier binfmt check (which pulled both arches)
42+
# leaves it pointing at whichever it pulled last - `docker run --platform`
43+
# then silently reuses that wrong-arch image. Re-pulling per iteration keeps
44+
# the local tag in sync with $platform.
45+
docker pull --quiet --platform "$platform" "$IMAGE" >/dev/null
46+
# ARCH_LABEL is passed explicitly so the container never has to guess its arch
47+
# from `uname -m` (unreliable under emulation). :z relabels the bind mount for
48+
# SELinux (Fedora/RHEL); externals/ is mounted read-only and copied out before
49+
# building.
4250
docker run --rm --platform "$platform" \
51+
-e ARCH_LABEL="$label" \
4352
-v "$HERE":/work:z \
4453
-v "$REPO/externals":/externals:ro,z \
4554
"$IMAGE" sh /work/build-in-container.sh

0 commit comments

Comments
 (0)