From 1999f9652333f4bcb9b754006eeb46e5f0f207a7 Mon Sep 17 00:00:00 2001 From: Yago Iglesias Date: Fri, 1 Sep 2023 22:44:42 +0200 Subject: [PATCH] feat(dockerfile): Improve size and layering --- .dockerignore | 3 --- Dockerfile | 27 ++++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/.dockerignore b/.dockerignore index 543635d..5d2a7ec 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,8 +1,5 @@ .env -.dockerignore -spec.yaml target/ -deploy/ tests/ Dockerfile scripts/ diff --git a/Dockerfile b/Dockerfile index a6ac04a..bbe93b4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,30 @@ -FROM rust:1.71.0 +FROM lukemathwalker/cargo-chef:latest-rust-1.71 as chef + WORKDIR /app RUN apt update && apt install lld clang -y + +FROM chef as planner +COPY . . +RUN cargo chef prepare --recipe-path recipe.json + +FROM chef as builder +COPY --from=planner /app/recipe.json recipe.json +RUN cargo chef cook --release --recipe-path recipe.json COPY . . ENV SQLX_OFFLINE true -RUN cargo build --release +RUN cargo build --release --bin zero2prod + + +FROM debian:bullseye-slim AS runtime + +WORKDIR /app +RUN apt-get update -y \ + && apt-get install -y --no-install-recommends openssl ca-certificates \ + && apt-get autoremove -y \ + && apt-get clean -y \ + && rm -rf /var/lib/apt/lists/* +COPY --from=builder /app/target/release/zero2prod zero2prod +COPY configuration configuration ENV APP_ENVIRONMENT production -ENTRYPOINT ["./target/release/zero2prod"] +ENTRYPOINT ["./zero2prod"]