diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml index 3f98ba5c..47429800 100644 --- a/.github/actions/build/action.yml +++ b/.github/actions/build/action.yml @@ -22,7 +22,7 @@ runs: - name: "Install QEMU" run: | set -x - if [[ "${{ inputs.platform }}" == "arm64" && "$(uname -m)" != "aarch64" ]]; then + if [[ "${{ inputs.platform }}" != "$(dpkg --print-architecture)" ]]; then echo "Installing QEMU" sudo apt-get update -qq && sudo apt-get install -y qemu-user-static else diff --git a/mkimage b/mkimage index 7a657f0e..471fb105 100755 --- a/mkimage +++ b/mkimage @@ -23,7 +23,15 @@ cp -a "${ROOT}/debootstrap/"* "${DEBOOTSTRAP_DIR}/scripts" KEYRING=$DEBOOTSTRAP_DIR/debian-archive-keyring.gpg use_qemu_static() { - [[ "$PLATFORM" == "arm64" && ! ( "$(uname -m)" == *arm* || "$(uname -m)" == *aarch64* ) ]] + [[ "$PLATFORM" != "$(dpkg --print-architecture)" ]] +} + +qemu_static_arch() { + case "$PLATFORM" in + amd64) echo x86_64 ;; + arm64) echo aarch64 ;; + *) echo "$PLATFORM" ;; + esac } export DEBIAN_FRONTEND=noninteractive @@ -60,10 +68,10 @@ rootfs_chroot() { if use_qemu_static ; then echo "Setting up qemu static in chroot" usr_bin_modification_time=$(stat -c %y "$rootfsDir"/usr/bin) - if [ -f "/usr/bin/qemu-aarch64-static" ]; then + if [ -f "/usr/bin/qemu-$(qemu_static_arch)-static" ]; then find /usr/bin/ -type f -name 'qemu-*-static' -exec cp {} "$rootfsDir"/usr/bin/. \; else - echo "Cannot find aarch64 qemu static. Aborting..." >&2 + echo "Cannot find $(qemu_static_arch) qemu static. Aborting..." >&2 exit 1 fi touch -d "$usr_bin_modification_time" "$rootfsDir"/usr/bin diff --git a/test b/test index 101fa439..e201d564 100755 --- a/test +++ b/test @@ -18,16 +18,12 @@ function test() { bind_mounts=( ) docker_platform_args=( ) -if [[ "$PLATFORM" == "arm64" ]]; then - if [[ "$(uname -m)" == *arm* || "$(uname -m)" == *aarch64* ]]; then - echo "Running in arm host. QEMU is not needed" - else - echo "Setting up qemu static" - for qemu_static_file in /usr/bin/qemu-*-static; do - bind_mounts+=( -v="$qemu_static_file:$qemu_static_file" ) - done - docker_platform_args+=( --platform "linux/arm64" ) - fi +if [[ "$PLATFORM" != "$(dpkg --print-architecture)" ]]; then + echo "Setting up qemu static" + for qemu_static_file in /usr/bin/qemu-*-static; do + bind_mounts+=( -v="$qemu_static_file:$qemu_static_file" ) + done + docker_platform_args+=( --platform "linux/$PLATFORM" ) fi function test_extra_args() {