|
1 | 1 | # build stage |
2 | | -FROM rustlang/rust:nightly-slim as build |
| 2 | +FROM rust:slim as build |
3 | 3 |
|
4 | | -# install libpq |
5 | | -RUN apt-get update |
6 | | -RUN apt-get install -y libpq-dev |
7 | | -RUN rm -rf /var/lib/apt/lists/* |
8 | | - |
9 | | -# create new empty binary project |
10 | | -RUN USER=root cargo new --bin app |
| 4 | +# install libpq and create new empty binary project |
| 5 | +RUN apt-get update; \ |
| 6 | + apt-get install --no-install-recommends -y libpq-dev; \ |
| 7 | + rm -rf /var/lib/apt/lists/*; \ |
| 8 | + USER=root cargo new --bin app |
11 | 9 | WORKDIR /app |
12 | 10 |
|
13 | 11 | # copy manifests |
14 | 12 | COPY ./Cargo.toml ./Cargo.toml |
15 | 13 |
|
16 | 14 | # build this project to cache dependencies |
17 | | -RUN cargo build --release |
18 | | -RUN rm src/*.rs |
| 15 | +RUN cargo build --release; \ |
| 16 | + rm src/*.rs |
19 | 17 |
|
20 | 18 | # copy project source and necessary files |
21 | 19 | COPY ./src ./src |
22 | 20 | COPY ./migrations ./migrations |
23 | 21 | COPY ./diesel.toml . |
24 | 22 |
|
25 | 23 | # add .env and secret.key for Docker env |
26 | | -RUN touch .env |
27 | | -RUN mv src/secret.key.sample src/secret.key |
| 24 | +RUN touch .env; \ |
| 25 | + mv src/secret.key.sample src/secret.key |
28 | 26 |
|
29 | 27 | # rebuild app with project source |
30 | | -RUN rm ./target/release/deps/actix_web_rest_api_with_jwt* |
31 | | -RUN cargo build --release |
| 28 | +RUN rm ./target/release/deps/actix_web_rest_api_with_jwt*; \ |
| 29 | + cargo build --release |
32 | 30 |
|
33 | 31 | # deploy stage |
34 | | -FROM debian:stretch-slim |
| 32 | +FROM debian:buster-slim |
35 | 33 |
|
36 | 34 | # create app directory |
37 | 35 | RUN mkdir app |
38 | 36 | WORKDIR /app |
39 | 37 |
|
40 | 38 | # install libpq |
41 | | -RUN apt-get update |
42 | | -RUN apt-get install -y libpq-dev |
43 | | -RUN rm -rf /var/lib/apt/lists/* |
| 39 | +RUN apt-get update; \ |
| 40 | + apt-get install --no-install-recommends -y libpq-dev; \ |
| 41 | + rm -rf /var/lib/apt/lists/* |
44 | 42 |
|
45 | 43 | # copy binary and configuration files |
46 | 44 | COPY --from=build /app/target/release/actix-web-rest-api-with-jwt . |
|
0 commit comments