From a25cb5a7ef9189ba68195a0efd4a7e85dea15d7f Mon Sep 17 00:00:00 2001 From: Sandro Eiler Date: Wed, 7 Feb 2024 12:14:51 +0100 Subject: [PATCH] build: reduce podman/docker image size --- .dockerignore | 6 ++++++ Dockerfile | 16 ++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..5d2a7ec --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +.env +target/ +tests/ +Dockerfile +scripts/ +migrations/ diff --git a/Dockerfile b/Dockerfile index 31f71e2..c72c594 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,20 @@ -FROM docker.io/rust:1.75.0 +# Builder stage +FROM rust:1.75.0 AS builder + WORKDIR /app RUN apt update && apt install lld clang -y COPY . . ENV SQLX_OFFLINE true RUN cargo build --release + +# Runtime stage +FROM rust:1.75.0-slim AS runtime + +WORKDIR /app +# Copy the compiled binary from the builder environment +# to our runtime environment +COPY --from=builder /app/target/release/learn_axum zero2prod +# We need the configuration file at runtime! +COPY configuration configuration ENV APP_ENVIRONMENT production -ENTRYPOINT ["./target/release/learn_axum"] +ENTRYPOINT ["./zero2prod"]