Last active
May 24, 2024 01:34
-
-
Save tuna2134/05fa09ee1d519a34ef7df9c4c6e81a3d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM rust:slim AS builder | |
WORKDIR /src/builder | |
ARG TARGETARCH | |
RUN if [ $TARGETARCH = "amd64" ]; then \ | |
echo "x86_64" > /tmp/arch; \ | |
elif [ $TARGETARCH = "arm64" ]; then \ | |
echo "aarch64" > /tmp/arch; \ | |
else \ | |
echo "Unsupported platform"; \ | |
exit 1; \ | |
fi | |
RUN apt-get update && apt-get install -y musl-tools | |
RUN rustup target add x86_64-unknown-linux-musl | |
COPY . . | |
RUN --mount=type=cache,target=/src/builder/target/ cargo build --target=$(cat /tmp/arch)-unknown-linux-musl --release && \ | |
cp target/$(cat /tmp/arch)-unknown-linux-musl/release/hello /tmp/hello | |
FROM scratch | |
WORKDIR /src/app | |
COPY --from=builder /tmp/hello . | |
CMD ["./hello"] |
Author
tuna2134
commented
May 24, 2024
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment