Skip to content

Commit

Permalink
fix: Dockerfile build $BUILDPLATFORM
Browse files Browse the repository at this point in the history
use the $BUILDPLATFORM env instead of hardcoding it, rename platform.sh to target.sh
  • Loading branch information
mrjackwills committed Nov 29, 2024
1 parent 7d3ba6d commit b7f671f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions containerised/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## Builder ##
#############

FROM --platform=linux/amd64 rust:slim AS builder
FROM --platform=$BUILDPLATFORM rust:slim AS builder

ARG TARGETARCH

Expand All @@ -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

Expand All @@ -29,10 +29,10 @@ COPY Cargo.* /usr/src/havn/
WORKDIR /usr/src/havn

# 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/havn/src/
Expand All @@ -41,9 +41,9 @@ COPY src /usr/src/havn/src/
RUN touch /usr/src/havn/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/havn/target/$(cat /.platform)/release/havn /
RUN cp /usr/src/havn/target/$(cat /.target)/release/havn /

#############
## Runtime ##
Expand Down
6 changes: 3 additions & 3 deletions containerised/platform.sh → containerised/target.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
case $TARGETARCH in

"amd64")
echo "x86_64-unknown-linux-musl" >/.platform
echo "x86_64-unknown-linux-musl" >/.target
echo "" >/.compiler
;;
"arm64")
echo "aarch64-unknown-linux-musl" >/.platform
echo "aarch64-unknown-linux-musl" >/.target
echo "gcc-aarch64-linux-gnu" >/.compiler
;;
"arm")
echo "arm-unknown-linux-musleabihf" >/.platform
echo "arm-unknown-linux-musleabihf" >/.target
echo "gcc-arm-linux-gnueabihf" >/.compiler
;;
esac

0 comments on commit b7f671f

Please sign in to comment.