From ac8af1b1d2443e4d5838ffd4140046a7a5595ab2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=B3=E3=83=9E=E3=83=AA=E3=83=B3=E8=A6=AA=E8=A1=9B?= =?UTF-8?q?=E9=9A=8A?= Date: Sun, 4 Feb 2024 01:41:29 +0900 Subject: [PATCH] Update Dockerfile --- Dockerfile | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index d87d1c9..1599033 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,28 @@ -FROM rust AS builder +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 aarch64-unknown-linux-musl +RUN rustup target add $(cat /tmp/arch)-unknown-linux-musl COPY . . -RUN --mount=type=cache,target=/src/builder/target/ cargo build --target=aarch64-unknown-linux-musl --release && \ - cp target/aarch64-unknown-linux-musl/release/expander /tmp/expander +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/expander /tmp/expander -FROM alpine +FROM scratch WORKDIR /src/app -RUN apk add ca-certificates COPY --from=builder /tmp/expander . CMD ["./expander"]