File tree Expand file tree Collapse file tree 2 files changed +75
-0
lines changed Expand file tree Collapse file tree 2 files changed +75
-0
lines changed Original file line number Diff line number Diff line change 1+ # build stage
2+ FROM rustlang/rust:nightly-slim as build
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
11+ WORKDIR /app
12+
13+ # copy manifests
14+ COPY ./Cargo.toml ./Cargo.toml
15+
16+ # build this project to cache dependencies
17+ RUN cargo build --release
18+ RUN rm src/*.rs
19+
20+ # copy project source and necessary files
21+ COPY ./src ./src
22+ COPY ./migrations ./migrations
23+ COPY ./diesel.toml .
24+
25+ # add .env and secret.key for Docker env
26+ RUN touch .env
27+ RUN mv src/secret.key.sample src/secret.key
28+
29+ # rebuild app with project source
30+ RUN rm ./target/release/deps/actix_web_rest_api_with_jwt*
31+ RUN cargo build --release
32+
33+ # deploy stage
34+ FROM debian:stretch-slim
35+
36+ # create app directory
37+ RUN mkdir app
38+ WORKDIR /app
39+
40+ # install libpq
41+ RUN apt-get update
42+ RUN apt-get install -y libpq-dev
43+ RUN rm -rf /var/lib/apt/lists/*
44+
45+ # copy binary and configuration files
46+ COPY --from=build /app/target/release/actix-web-rest-api-with-jwt .
47+ COPY --from=build /app/.env .
48+ COPY --from=build /app/diesel.toml .
49+
50+ # expose port
51+ EXPOSE 8000
52+
53+ # run the binary
54+ ENTRYPOINT ["/app/actix-web-rest-api-with-jwt" ]
Original file line number Diff line number Diff line change 1+ version : ' 3'
2+ services :
3+ db :
4+ container_name : address_book_db
5+ image : postgres
6+ restart : always
7+ ports :
8+ - " 5432:5432"
9+ environment :
10+ - POSTGRES_PASSWORD=postgres
11+ app :
12+ build : .
13+ restart : always
14+ ports :
15+ - " 8000:8000"
16+ environment :
17+ - APP_HOST=0.0.0.0
18+ - APP_PORT=8000
19+ - DATABASE_URL=postgres://postgres:postgres@db/postgres
20+ depends_on :
21+ - db
You can’t perform that action at this time.
0 commit comments