Skip to content

Commit

Permalink
refactor: add Dockerfile multi stages (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jayllyz authored Jun 24, 2024
1 parent f1d3c90 commit 4d8b120
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
23 changes: 18 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4d8b120

Please sign in to comment.