From be1c7536c245061b3c98ed79d118e9e9b6f02a4b Mon Sep 17 00:00:00 2001 From: Antony DAVID Date: Mon, 24 Jun 2024 10:38:55 +0200 Subject: [PATCH] refactor: Dockerfile stages --- Dockerfile | 23 ++++++++++++++++++----- README.md | 6 +++++- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index b59f084..dbbd7ff 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,24 @@ -FROM rust:1-slim - +FROM rust:1 AS base WORKDIR /app +FROM base AS dev +RUN cargo install cargo-watch COPY . . +CMD ["cargo", "watch", "-x", "run"] -RUN cargo build +FROM base AS planner +RUN cargo install cargo-chef +COPY . . +RUN cargo chef prepare --recipe-path recipe.json -EXPOSE 8000 +FROM base AS build +COPY --from=planner /app/recipe.json recipe.json +RUN cargo chef cook --release --recipe-path recipe.json +COPY . . +RUN cargo build --release --bin sudoku-rust -CMD ["cargo", "run"] + +FROM debian:stable-slim AS prod +WORKDIR /app +COPY --from=build /app/target/release/sudoku-rust /usr/local/bin +ENTRYPOINT ["/usr/local/bin/app"] diff --git a/README.md b/README.md index c04d4f7..e4826f8 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,11 @@ Go to the project directory Build the docker image ```bash - docker build -t sudoku-rust . + # with live reload + docker build -t sudoku-rust --target=dev . + + # release optimized + docker build -t sudoku-rust --target=prod . ``` Run the docker container