Dockerfile: let Rustup handle architecture detection

More flexible as the build process will now automatically adapt to whatever architecture the container is being built on, without needing to explicitly list out each supported architecture
This commit is contained in:
perennial 2024-08-13 23:33:32 +10:00
parent 0b8ddf77b7
commit 6a07a2f47c
No known key found for this signature in database
GPG key ID: 826BC6E6B83E08E7

View file

@ -19,18 +19,8 @@ ENV OPENSSL_DIR=/usr
# Copy the current directory contents into the container
COPY . .
# Set up build arguments for architecture detection
ARG TARGETARCH
# Set the Rust target based on the detected architecture
RUN case "$TARGETARCH" in \
"amd64") echo "x86_64-unknown-linux-musl" > /tmp/target ;; \
"arm64") echo "aarch64-unknown-linux-musl" > /tmp/target ;; \
*) echo "Unsupported architecture: $TARGETARCH" && exit 1 ;; \
esac
# Add the target to rustup and build the application
RUN RUST_TARGET=$(cat /tmp/target) && \
# Determine the target architecture and build the application
RUN RUST_TARGET=$(rustc -vV | sed -n 's/host: //p') && \
rustup target add $RUST_TARGET && \
RUSTFLAGS='-C target-feature=+crt-static' cargo build --release --target $RUST_TARGET