From ee80e671335266f2065620e1d2c99872e86d1e5d Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Fri, 10 Dec 2021 11:22:04 +0100 Subject: [PATCH] ci: Run tests on all platforms in the Docker image --- Dockerfile | 24 +++++++++++++++++++++++- docker-bake.hcl | 11 ++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 529573929..100d8b924 100644 --- a/Dockerfile +++ b/Dockerfile @@ -37,6 +37,7 @@ RUN apt update && apt install -y --no-install-recommends \ libc6-dev-arm64-cross \ libc6-dev-amd64-cross \ libc6-dev-armhf-cross \ + qemu-user \ && rm -rf /var/lib/apt/lists/* WORKDIR /app @@ -44,15 +45,19 @@ RUN cargo install --locked cargo-chef ENV \ CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-linux-gnu-gcc \ + CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER="qemu-x86_64 -L /usr/x86_64-linux-gnu" \ CC_x86_64_unknown_linux_gnu=x86_64-linux-gnu-gcc \ CXX_x86_64_unknown_linux_gnu=x86_64-linux-gnu-g++ \ CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc \ + CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER="qemu-aarch64 -L /usr/aarch64-linux-gnu" \ CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc \ CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++ \ CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc \ + CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABIHF_RUNNER="qemu-arm -L /usr/arm-linux-gnueabihf" \ CC_arm_unknown_linux_gnueabihf=arm-linux-gnueabihf-gcc \ CXX_arm_unknown_linux_gnueabihf=arm-linux-gnueabihf-g++ \ CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc \ + CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_RUNNER="qemu-arm -L /usr/arm-linux-gnueabihf" \ CC_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-gcc \ CXX_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-g++ @@ -75,7 +80,7 @@ COPY . . RUN cargo chef prepare --recipe-path recipe.json ## Actual build stage ## -FROM --platform=${BUILDPLATFORM} chef AS builder +FROM --platform=${BUILDPLATFORM} chef AS builder ARG TARGETPLATFORM @@ -97,6 +102,23 @@ RUN cargo build \ # Move the binary to avoid having to guess its name in the next stage RUN mv target/$(/docker-arch-to-rust-target.sh "${TARGETPLATFORM}")/release/mas-cli /mas-cli +## Stage to run unit tests ## +FROM --platform=${BUILDPLATFORM} chef AS test + +ARG TARGETPLATFORM + +# Build dependencies +COPY --from=planner /app/recipe.json recipe.json +RUN cargo chef cook \ + --recipe-path recipe.json \ + --target $(/docker-arch-to-rust-target.sh "${TARGETPLATFORM}") + +# Run the tests +COPY . . +COPY --from=static-files /app/crates/static-files/public /app/crates/static-files/public +RUN cargo test \ + --target $(/docker-arch-to-rust-target.sh "${TARGETPLATFORM}") + ## Runtime stage, debug variant ## FROM --platform=${TARGETPLATFORM} gcr.io/distroless/cc-debian${DEBIAN_VERSION}:debug-nonroot AS debug COPY --from=builder /mas-cli /mas-cli diff --git a/docker-bake.hcl b/docker-bake.hcl index 92d9b1da5..d96a1dcfd 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -12,6 +12,11 @@ target "debug" { target = "debug" } +target "test" { + inherits = ["default"] + target = "test" +} + target "release" { inherits = ["default"] platforms = [ @@ -22,7 +27,7 @@ target "release" { } // This is what is baked by GitHub Actions -group "gha" { targets = ["gha-regular", "gha-debug"] } +group "gha" { targets = ["gha-regular", "gha-debug", "gha-test"] } target "gha-base" { inherits = ["release"] @@ -37,3 +42,7 @@ target "gha-regular" { target "gha-debug" { inherits = ["gha-base", "debug", "docker-metadata-action-debug"] } + +target "gha-test" { + inherits = ["gha-base", "test"] +}