diff --git a/Dockerfile b/Dockerfile index 426de9c..2c68f0b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,21 @@ -FROM rust:1.70 as builder +FROM --platform=$BUILDPLATFORM rust:1.70 as cross +ARG TARGETARCH +COPY docker/platform.sh . +RUN ./platform.sh # should write /.platform and /.compiler +RUN rustup target add $(cat /.platform) +RUN apt update && apt-get install -y unzip $(cat /.compiler) RUN USER=root cargo new --bin ics-adapter WORKDIR ./ics-adapter COPY ./Cargo.toml ./Cargo.toml -RUN cargo build --release +RUN cargo build --release --target $(cat /.platform) RUN rm src/*.rs ADD . ./ RUN rm ./target/release/deps/ics_adapter* -RUN cargo build --release +RUN cargo build --release --target $(cat /.platform) +RUN cp /usr/src/trow/target/$(cat /.platform)/release/ics-adapter /ics-adapter.bin # Get rid of this when build --out is stable FROM debian:buster-slim @@ -28,7 +34,7 @@ RUN groupadd $APP_USER \ && useradd -g $APP_USER $APP_USER \ && mkdir -p ${APP} -COPY --from=builder /ics-adapter/target/release/ics-adapter ${APP}/ics-adapter +COPY --from=cross /ics-adapter.bin ${APP}/ics-adapter RUN chown -R $APP_USER:$APP_USER ${APP} diff --git a/docker/platform.sh b/docker/platform.sh new file mode 100755 index 0000000..635e41f --- /dev/null +++ b/docker/platform.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# Used in Docker build to set platform dependent variables + +case $TARGETARCH in + + "amd64") + echo "x86_64-unknown-linux-gnu" > /.platform + echo "" > /.compiler + ;; + "arm64") + echo "aarch64-unknown-linux-gnu" > /.platform + echo "gcc-aarch64-linux-gnu" > /.compiler + ;; + "arm") + echo "armv7-unknown-linux-gnueabihf" > /.platform + echo "gcc-arm-linux-gnueabihf" > /.compiler + ;; +esac