|
1 | | -# build stage |
2 | | -FROM rust:slim as build |
3 | | - |
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 |
9 | | -WORKDIR /app |
10 | | - |
11 | | -# copy manifests |
12 | | -COPY ./Cargo.toml ./Cargo.toml |
13 | | - |
14 | | -# build this project to cache dependencies |
15 | | -RUN cargo build --release; \ |
16 | | - rm src/*.rs |
17 | | - |
18 | | -# copy project source and necessary files |
19 | | -COPY ./src ./src |
20 | | -COPY ./migrations ./migrations |
21 | | -COPY ./diesel.toml . |
22 | | - |
23 | | -# add .env and secret.key for Docker env |
24 | | -RUN touch .env; \ |
25 | | - mv src/secret.key.sample src/secret.key |
26 | | - |
27 | | -# rebuild app with project source |
28 | | -RUN rm ./target/release/deps/actix_web_rest_api_with_jwt*; \ |
29 | | - cargo build --release |
30 | | - |
31 | | -# deploy stage |
32 | | -FROM debian:buster-slim |
33 | | - |
34 | | -# create app directory |
35 | | -RUN mkdir app |
36 | | -WORKDIR /app |
37 | | - |
38 | | -# install libpq |
39 | | -RUN apt-get update; \ |
40 | | - apt-get install --no-install-recommends -y libpq-dev; \ |
41 | | - rm -rf /var/lib/apt/lists/* |
42 | | - |
43 | | -# copy binary and configuration files |
44 | | -COPY --from=build /app/target/release/actix-web-rest-api-with-jwt . |
45 | | -COPY --from=build /app/.env . |
46 | | -COPY --from=build /app/diesel.toml . |
47 | | - |
48 | | -# expose port |
49 | | -EXPOSE 8000 |
50 | | - |
51 | | -# run the binary |
52 | | -ENTRYPOINT ["/app/actix-web-rest-api-with-jwt"] |
| 1 | +# build stage |
| 2 | +FROM rust:slim as build |
| 3 | + |
| 4 | +# install libpq, libsqlite and create new empty binary project |
| 5 | +RUN apt-get update; \ |
| 6 | + apt-get install --no-install-recommends -y libpq-dev libsqlite3-dev; \ |
| 7 | + rm -rf /var/lib/apt/lists/*; \ |
| 8 | + USER=root cargo new --bin app |
| 9 | +WORKDIR /app |
| 10 | + |
| 11 | +# copy manifests |
| 12 | +COPY ./Cargo.toml ./Cargo.toml |
| 13 | + |
| 14 | +# build this project to cache dependencies |
| 15 | +RUN cargo build; \ |
| 16 | + rm src/*.rs |
| 17 | + |
| 18 | +# copy project source and necessary files |
| 19 | +COPY ./src ./src |
| 20 | +COPY ./migrations ./migrations |
| 21 | +COPY ./diesel.toml . |
| 22 | + |
| 23 | +# add .env and secret.key for Docker env |
| 24 | +RUN touch .env; \ |
| 25 | + mv src/secret.key.sample src/secret.key |
| 26 | + |
| 27 | +# rebuild app with project source |
| 28 | +RUN rm ./target/debug/deps/actix_web_rest_api_with_jwt*; \ |
| 29 | + cargo build |
| 30 | + |
| 31 | +# deploy stage |
| 32 | +FROM debian:buster-slim |
| 33 | + |
| 34 | +# create app directory |
| 35 | +RUN mkdir app |
| 36 | +WORKDIR /app |
| 37 | + |
| 38 | +# install libpq and libsqlite |
| 39 | +RUN apt-get update; \ |
| 40 | + apt-get install --no-install-recommends -y libpq5 libsqlite3-0; \ |
| 41 | + rm -rf /var/lib/apt/lists/* |
| 42 | + |
| 43 | +# copy binary and configuration files |
| 44 | +COPY --from=build /app/target/debug/actix-web-rest-api-with-jwt . |
| 45 | +COPY --from=build /app/.env . |
| 46 | +COPY --from=build /app/diesel.toml . |
| 47 | +COPY ./wait-for-it.sh . |
| 48 | + |
| 49 | +# expose port |
| 50 | +EXPOSE 8000 |
| 51 | + |
| 52 | +# run the binary |
| 53 | +CMD ["./wait-for-it.sh", "db:5432", "--", "/app/actix-web-rest-api-with-jwt"] |
0 commit comments