Skip to content

Instantly share code, notes, and snippets.

@tuna2134
Last active May 24, 2024 01:34
Show Gist options
  • Save tuna2134/05fa09ee1d519a34ef7df9c4c6e81a3d to your computer and use it in GitHub Desktop.
Save tuna2134/05fa09ee1d519a34ef7df9c4c6e81a3d to your computer and use it in GitHub Desktop.
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"]
@tuna2134
Copy link
Author

tuna2134 commented May 24, 2024

FROM rust:slim AS builder

WORKDIR /src/builder

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=x86_64-unknown-linux-musl --release && \
  cp target/x86_64-unknown-linux-musl/release/musicbot /tmp/musicbot

FROM scratch

WORKDIR /src/app

COPY --from=builder /tmp/musicbot .

CMD ["./musicbot"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment