Add fail-safe to test the image architecture

Verify that the target image architecture matches what is expected
according to the balena app architecture.

Change-type: patch
This commit is contained in:
Felipe Lalanne 2023-03-27 12:14:01 -03:00 committed by Kyle Harding
parent c1b157971d
commit 1cf325d5c5
2 changed files with 28 additions and 0 deletions

View File

@ -133,6 +133,10 @@ COPY typings ./typings
COPY src ./src
COPY test ./test
# Fail-safe, check the architecture used by apk against the expected architecture
# from the device type
RUN APK_ARCH=$(./build-utils/apk-print-arch.sh); [ "$APK_ARCH" = "$ARCH" ] || (echo "Image architecture ($APK_ARCH) does not match the target architecture ($ARCH)" && exit 1)
# Run type checking and unit tests here
# to prevent setting up a test environment that will
# most likely fail.

24
build-utils/apk-print-arch.sh Executable file
View File

@ -0,0 +1,24 @@
#!/bin/sh
# detect-arch.sh
apk_arch=$(apk --print-arch)
case $apk_arch in
x86_64)
printf "amd64"
;;
aarch64)
printf "aarch64"
;;
armv7)
printf "armv7hf"
;;
armhf)
printf "rpi"
;;
x86)
printf "i386"
;;
*)
printf "%s" "$apk_arch"
;;
esac