Drastically reduce the Docker image size to 1.56MB

This commit is contained in:
2023-03-22 16:56:17 +01:00
parent 8199cffdf1
commit 274661171b
2 changed files with 10 additions and 6 deletions

View File

@@ -1,3 +1,7 @@
[profile.release]
strip = true
panic = "abort"
[workspace]
members = [
"board-shared",

View File

@@ -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"]