diff --git a/Dockerfile.template b/Dockerfile.template index 6968d1d4..6a4931fc 100644 --- a/Dockerfile.template +++ b/Dockerfile.template @@ -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. diff --git a/build-utils/apk-print-arch.sh b/build-utils/apk-print-arch.sh new file mode 100755 index 00000000..3728e18b --- /dev/null +++ b/build-utils/apk-print-arch.sh @@ -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