From 0c6f53228f01196e352c2069383ba1e7a10950a8 Mon Sep 17 00:00:00 2001 From: Jack Wills <32690432+mrjackwills@users.noreply.github.com> Date: Tue, 19 Nov 2024 08:25:55 +0000 Subject: [PATCH] fix: update containerised Dockerfile --- containerised/Dockerfile | 14 +++++++------- containerised/target.sh | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 containerised/target.sh diff --git a/containerised/Dockerfile b/containerised/Dockerfile index 3c2c7b8..e05760a 100644 --- a/containerised/Dockerfile +++ b/containerised/Dockerfile @@ -2,7 +2,7 @@ ## Builder ## ############# -FROM --platform=linux/amd64 rust:slim AS builder +FROM --platform=$BUILDPLATFORM rust:slim AS builder ARG TARGETARCH @@ -11,9 +11,9 @@ ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER="aarch64-linux-gnu-gcc" ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUSTFLAGS="-C target-feature=+crt-static -C link-arg=-lgcc" ENV CARGO_TARGET_ARM_UNKNOWN_LINUX_MUSLEABIHF_LINKER="arm-linux-gnueabihf-ld" -COPY ./containerised/platform.sh . +COPY ./containerised/target.sh . -RUN chmod +x ./platform.sh && ./platform.sh +RUN chmod +x ./target.sh && ./target.sh RUN apt-get update && apt-get install $(cat /.compiler) -y @@ -29,10 +29,10 @@ COPY Cargo.* /usr/src/oxker/ WORKDIR /usr/src/oxker # Install target platform (Cross-Compilation) -RUN rustup target add $(cat /.platform) +RUN rustup target add $(cat /.target) # This is a dummy build to get the dependencies cached - probably not needed - as run via a github action -RUN cargo build --target $(cat /.platform) --release +RUN cargo build --target $(cat /.target) --release # Now copy in the rest of the sources COPY src /usr/src/oxker/src/ @@ -41,9 +41,9 @@ COPY src /usr/src/oxker/src/ RUN touch /usr/src/oxker/src/main.rs # This is the actual application build -RUN cargo build --release --target $(cat /.platform) +RUN cargo build --release --target $(cat /.target) -RUN cp /usr/src/oxker/target/$(cat /.platform)/release/oxker / +RUN cp /usr/src/oxker/target/$(cat /.target)/release/oxker / ############# ## Runtime ## diff --git a/containerised/target.sh b/containerised/target.sh new file mode 100644 index 0000000..40ba3d6 --- /dev/null +++ b/containerised/target.sh @@ -0,0 +1,18 @@ +#!/bin/sh +# Used in Docker build to set platform dependent variables + +case $TARGETARCH in + +"amd64") + echo "x86_64-unknown-linux-musl" >/.target + echo "" >/.compiler + ;; +"arm64") + echo "aarch64-unknown-linux-musl" >/.target + echo "gcc-aarch64-linux-gnu" >/.compiler + ;; +"arm") + echo "arm-unknown-linux-musleabihf" >/.target + echo "gcc-arm-linux-gnueabihf" >/.compiler + ;; +esac