Skip to content

Commit f35d763

Browse files
committed
Add volume for address book db
1 parent a586fc3 commit f35d763

File tree

5 files changed

+84
-76
lines changed

5 files changed

+84
-76
lines changed

.github/workflows/docker_action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
mkdir app
6565
cp target/release/actix-web-rest-api-with-jwt app/actix-web-rest-api-with-jwt
6666
cp diesel.toml app/diesel.toml
67-
cp docker/prod/Dockerfile app/Dockerfile
67+
cp Dockerfile.prod app/Dockerfile
6868
cd app
6969
touch .env
7070
tar -czvf ../app.tar.gz .
Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
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 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
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+
48+
# expose port
49+
EXPOSE 8000
50+
51+
# run the binary
52+
ENTRYPOINT ["/app/actix-web-rest-api-with-jwt"]
Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
# base image
2-
FROM debian:buster-slim
3-
4-
# create app directory
5-
RUN mkdir app
6-
WORKDIR /app
7-
8-
# install libpq
9-
RUN apt-get update; \
10-
apt-get install --no-install-recommends -y libpq-dev; \
11-
rm -rf /var/lib/apt/lists/*
12-
13-
# copy binary and configuration files
14-
COPY ./actix-web-rest-api-with-jwt .
15-
COPY ./diesel.toml .
16-
COPY ./.env .
17-
18-
# expose port
19-
EXPOSE 8000
20-
21-
# run the binary
22-
ENTRYPOINT ["/app/actix-web-rest-api-with-jwt"]
1+
# base image
2+
FROM debian:buster-slim
3+
4+
# create app directory
5+
RUN mkdir app
6+
WORKDIR /app
7+
8+
# install libpq
9+
RUN apt-get update; \
10+
apt-get install --no-install-recommends -y libpq5 libsqlite3-0; \
11+
rm -rf /var/lib/apt/lists/*
12+
13+
# copy binary and configuration files
14+
COPY ./actix-web-rest-api-with-jwt .
15+
COPY ./diesel.toml .
16+
COPY ./.env .
17+
18+
# expose port
19+
EXPOSE 8000
20+
21+
# run the binary
22+
ENTRYPOINT ["/app/actix-web-rest-api-with-jwt"]

docker-compose.local.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ services:
88
- "5432:5432"
99
environment:
1010
- POSTGRES_PASSWORD=postgres
11+
volumes:
12+
- pgdata:/var/lib/postgresql/data
1113
app:
1214
container_name: address_book_be
1315
build:
1416
context: .
15-
dockerfile: docker/local/Dockerfile
17+
dockerfile: Dockerfile.local
1618
restart: always
1719
ports:
1820
- "8000:8000"
@@ -22,3 +24,5 @@ services:
2224
- DATABASE_URL=postgres://postgres:postgres@db/postgres
2325
depends_on:
2426
- db
27+
volumes:
28+
pgdata:

docker-compose.prod.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ services:
88
- "5432:5432"
99
environment:
1010
- POSTGRES_PASSWORD=postgres
11+
volumes:
12+
- pgdata:/var/lib/postgresql/data
1113
app:
1214
container_name: address_book_be
1315
image: sakadream/actix-web-rest-api-with-jwt
@@ -20,3 +22,5 @@ services:
2022
- DATABASE_URL=postgres://postgres:postgres@db/postgres
2123
depends_on:
2224
- db
25+
volumes:
26+
pgdata:

0 commit comments

Comments
 (0)