From b9dae65fb7dbefd2502488b09e71a36c070b5e9c Mon Sep 17 00:00:00 2001 From: Hennik Hunsaker Date: Wed, 8 Dec 2021 09:02:59 -0700 Subject: [PATCH 1/3] Pass the arch to Docker --- .github/workflows/advanced-example.yml | 1 + .github/workflows/test.yml | 1 + src/run-on-arch.js | 15 ++++++++++++++- src/run-on-arch.sh | 21 +++++++++++++++------ 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/.github/workflows/advanced-example.yml b/.github/workflows/advanced-example.yml index 93842b57..8cb544ce 100644 --- a/.github/workflows/advanced-example.yml +++ b/.github/workflows/advanced-example.yml @@ -9,6 +9,7 @@ jobs: # Run steps on a matrix of 4 arch/distro combinations strategy: + fail-fast: false matrix: include: - arch: aarch64 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bfb5dec3..f7afe101 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,6 +7,7 @@ jobs: name: Test strategy: + fail-fast: false matrix: include: # The full matrix of Dockerfiles would be extensive, so just diff --git a/src/run-on-arch.js b/src/run-on-arch.js index d50b3a92..537ea004 100644 --- a/src/run-on-arch.js +++ b/src/run-on-arch.js @@ -9,6 +9,19 @@ function slug(str) { return str.replace(/[^a-zA-Z0-9]/g, '-').toLowerCase(); } +function docker_arch(qemu_arch) { + const matrix = { + 'i386': '386', + 'x86_64': 'amd64', + 'armv5': 'arm/v5', + 'armv6': 'arm/v6', + 'armv7': 'arm/v7', + 'aarch64': 'arm64', + }; + + return matrix[qemu_arch] || qemu_arch; +} + async function main() { if (process.platform !== 'linux') { throw new Error('run-on-arch supports only Linux') @@ -101,7 +114,7 @@ async function main() { console.log('Configuring Docker for multi-architecture support') await exec( path.join(__dirname, 'run-on-arch.sh'), - [ dockerFile, containerName, ...dockerRunArgs ], + [ docker_arch(arch), dockerFile, containerName, ...dockerRunArgs ], { env }, ); } diff --git a/src/run-on-arch.sh b/src/run-on-arch.sh index f2b385f3..da55dab7 100755 --- a/src/run-on-arch.sh +++ b/src/run-on-arch.sh @@ -3,10 +3,11 @@ set -euo pipefail # Args -DOCKERFILE=$1 -CONTAINER_NAME=$2 +TARGET_ARCH=$1 +DOCKERFILE=$2 +CONTAINER_NAME=$3 # Remainder of args get passed to docker -declare -a DOCKER_RUN_ARGS=${@:3:${#@}} +declare -a DOCKER_RUN_ARGS=${@:4:${#@}} # Defaults ACTION_DIR="$(cd "$(dirname "$0")"/.. >/dev/null 2>&1 ; pwd -P)" @@ -47,8 +48,9 @@ build_container () { # cached between builds. if [[ -z "${GITHUB_TOKEN:-}" ]] then - docker build \ + docker buildx build \ "${ACTION_DIR}/Dockerfiles" \ + --platform linux/$TARGET_ARCH \ --file "$DOCKERFILE" \ --tag "${CONTAINER_NAME}:latest" else @@ -68,8 +70,9 @@ build_container () { set "$BASH_FLAGS" docker pull "$PACKAGE_REGISTRY:latest" || true - docker build \ + docker buildx build \ "${ACTION_DIR}/Dockerfiles" \ + --platform linux/$TARGET_ARCH \ --file "$DOCKERFILE" \ --tag "${CONTAINER_NAME}:latest" \ --cache-from="$PACKAGE_REGISTRY" @@ -87,7 +90,8 @@ run_container () { # Interpolate DOCKER_RUN_ARGS, to support evaluation of $VAR references for i in "${!DOCKER_RUN_ARGS[@]}" do - DOCKER_RUN_ARGS[$i]=$(eval echo "${DOCKER_RUN_ARGS[$i]}") + # We have to do some ugly "magic" here to prevent flags from getting eaten + DOCKER_RUN_ARGS[$i]=$(eval echo _"${DOCKER_RUN_ARGS[$i]}" | sed s/^_//) done chmod +x "${ACTION_DIR}/src/run-on-arch-commands.sh" @@ -97,6 +101,7 @@ run_container () { docker run \ --workdir "${GITHUB_WORKSPACE}" \ + --platform linux/$TARGET_ARCH \ --rm \ -e DEBIAN_FRONTEND=noninteractive \ -e CI \ @@ -138,5 +143,9 @@ run_container () { quiet rm -f build-log.txt quiet install_deps +echo "::group::Build Container" build_container +echo "::endgroup::" +echo "::group::Run Container" run_container +echo "::endgroup::" From 9c19ac23d081ecc3c48f89ac56c2c5693d4a867a Mon Sep 17 00:00:00 2001 From: Hennik Hunsaker Date: Thu, 9 Dec 2021 21:29:36 -0700 Subject: [PATCH 2/3] Get archarm to build --- Dockerfiles/Dockerfile.aarch64.archarm_latest | 2 +- Dockerfiles/Dockerfile.armv7.archarm_latest | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfiles/Dockerfile.aarch64.archarm_latest b/Dockerfiles/Dockerfile.aarch64.archarm_latest index 4100aa31..e8e610fd 100644 --- a/Dockerfiles/Dockerfile.aarch64.archarm_latest +++ b/Dockerfiles/Dockerfile.aarch64.archarm_latest @@ -1,4 +1,4 @@ -FROM agners/archlinuxarm-arm64v8:latest +FROM danhunsaker/archlinuxarm-arm64v8:latest COPY ./run-on-arch-install.sh /root/run-on-arch-install.sh RUN chmod +x /root/run-on-arch-install.sh && /root/run-on-arch-install.sh diff --git a/Dockerfiles/Dockerfile.armv7.archarm_latest b/Dockerfiles/Dockerfile.armv7.archarm_latest index 370b12f8..cbc785b3 100644 --- a/Dockerfiles/Dockerfile.armv7.archarm_latest +++ b/Dockerfiles/Dockerfile.armv7.archarm_latest @@ -1,4 +1,4 @@ -FROM agners/archlinuxarm-arm32v7:latest +FROM danhunsaker/archlinuxarm-arm32v7:latest COPY ./run-on-arch-install.sh /root/run-on-arch-install.sh RUN chmod +x /root/run-on-arch-install.sh && /root/run-on-arch-install.sh From db46e59c1bbfa9b1ac5a3602a89df980cec23269 Mon Sep 17 00:00:00 2001 From: Hennik Hunsaker Date: Tue, 14 Dec 2021 23:31:54 -0700 Subject: [PATCH 3/3] Minor code tweaks --- src/run-on-arch.js | 6 +++--- src/run-on-arch.sh | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/run-on-arch.js b/src/run-on-arch.js index 537ea004..b0f81107 100644 --- a/src/run-on-arch.js +++ b/src/run-on-arch.js @@ -9,7 +9,7 @@ function slug(str) { return str.replace(/[^a-zA-Z0-9]/g, '-').toLowerCase(); } -function docker_arch(qemu_arch) { +function dockerArch(qemuArch) { const matrix = { 'i386': '386', 'x86_64': 'amd64', @@ -19,7 +19,7 @@ function docker_arch(qemu_arch) { 'aarch64': 'arm64', }; - return matrix[qemu_arch] || qemu_arch; + return matrix[qemuArch] || qemuArch; } async function main() { @@ -114,7 +114,7 @@ async function main() { console.log('Configuring Docker for multi-architecture support') await exec( path.join(__dirname, 'run-on-arch.sh'), - [ docker_arch(arch), dockerFile, containerName, ...dockerRunArgs ], + [ dockerArch(arch), dockerFile, containerName, ...dockerRunArgs ], { env }, ); } diff --git a/src/run-on-arch.sh b/src/run-on-arch.sh index da55dab7..02fb8f46 100755 --- a/src/run-on-arch.sh +++ b/src/run-on-arch.sh @@ -50,7 +50,7 @@ build_container () { then docker buildx build \ "${ACTION_DIR}/Dockerfiles" \ - --platform linux/$TARGET_ARCH \ + --platform "linux/${TARGET_ARCH}" \ --file "$DOCKERFILE" \ --tag "${CONTAINER_NAME}:latest" else @@ -72,7 +72,7 @@ build_container () { docker pull "$PACKAGE_REGISTRY:latest" || true docker buildx build \ "${ACTION_DIR}/Dockerfiles" \ - --platform linux/$TARGET_ARCH \ + --platform "linux/${TARGET_ARCH}" \ --file "$DOCKERFILE" \ --tag "${CONTAINER_NAME}:latest" \ --cache-from="$PACKAGE_REGISTRY" @@ -101,7 +101,7 @@ run_container () { docker run \ --workdir "${GITHUB_WORKSPACE}" \ - --platform linux/$TARGET_ARCH \ + --platform "linux/${TARGET_ARCH}" \ --rm \ -e DEBIAN_FRONTEND=noninteractive \ -e CI \