From 6baac1ac79b428f088a9593c038f4f921e17cc80 Mon Sep 17 00:00:00 2001 From: baalajimaestro Date: Sun, 4 Feb 2024 12:14:58 +0530 Subject: [PATCH] Build with crt-static Smallest dockerfile possible Signed-off-by: baalajimaestro --- Dockerfile | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index e8e72b1..db363a6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,25 @@ -FROM rust:bookworm as builder +FROM rust:alpine as builder + +RUN apk add musl-dev RUN mkdir /app WORKDIR /app +ARG RUSTFLAGS="-C target-feature=+crt-static" + COPY Cargo.toml /app COPY Cargo.lock /app COPY src /app/src COPY templates /app/templates -RUN cargo build --release -FROM gcr.io/distroless/cc-debian12:latest +RUN cargo build --release --target=x86_64-unknown-linux-musl + +RUN strip -s /app/target/x86_64-unknown-linux-musl/release/paste-frontend && \ + strip -R .comment -R .note -R .note.ABI-tag /app/target/x86_64-unknown-linux-musl/release/paste-frontend + +FROM scratch WORKDIR /app -COPY --from=builder /app/target/release/paste-frontend /app/paste-frontend +COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/paste-frontend /app/paste-frontend ADD templates /app/templates ADD static /app/static EXPOSE 8080