From 274661171bfd1facb9a9b61813afaf860fad7095 Mon Sep 17 00:00:00 2001 From: clfreville2 Date: Wed, 22 Mar 2023 16:56:17 +0100 Subject: [PATCH] Drastically reduce the Docker image size to 1.56MB --- Cargo.toml | 4 ++++ board-server/Dockerfile | 12 ++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3ba572e..d660e5d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,7 @@ +[profile.release] +strip = true +panic = "abort" + [workspace] members = [ "board-shared", diff --git a/board-server/Dockerfile b/board-server/Dockerfile index 69389f7..7b8bc11 100644 --- a/board-server/Dockerfile +++ b/board-server/Dockerfile @@ -3,21 +3,21 @@ FROM rust:1.68.0-slim as builder ENV CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse WORKDIR /usr/src/board +# Build with musl to statically link +RUN rustup target add x86_64-unknown-linux-musl + COPY Cargo.toml /usr/src/board/Cargo.toml COPY board-frontend /usr/src/board/board-frontend COPY board-network /usr/src/board/board-network COPY board-server /usr/src/board/board-server COPY board-shared /usr/src/board/board-shared -# Build with musl to run on Alpine -RUN rustup target add x86_64-unknown-linux-musl RUN cargo build --target x86_64-unknown-linux-musl --release --bin board-server +FROM scratch AS runtime -FROM alpine:3.17.2 AS runtime - -COPY --from=builder /usr/src/board/target/x86_64-unknown-linux-musl/release/board-server /usr/local/bin +COPY --from=builder /usr/src/board/target/x86_64-unknown-linux-musl/release/board-server / EXPOSE 8080 -ENTRYPOINT ["/usr/local/bin/board-server"] +ENTRYPOINT ["/board-server"]