Skip to content

Commit 28ed7db

Browse files
committed
Merge branch 'master' into update-dependencies
2 parents 01a5cac + 5454521 commit 28ed7db

File tree

7 files changed

+307
-82
lines changed

7 files changed

+307
-82
lines changed

.gitattributes

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.sh text eol=lf
2+
*.bash text eol=lf
3+
*.cmd text eol=crlf
4+
*.ps1 text eol=crlf

.github/workflows/docker_action.yml

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ 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.github-action app/Dockerfile
68+
cp wait-for-it.sh app/wait-for-it.sh
6869
cd app
6970
touch .env
7071
tar -czvf ../app.tar.gz .
@@ -76,7 +77,6 @@ jobs:
7677
name: artifact-linux-docker
7778
path: app.tar.gz
7879

79-
8080
cicd-docker:
8181
name: CICD Docker
8282
runs-on: ubuntu-latest
@@ -90,11 +90,39 @@ jobs:
9090
- name: Extract app archive
9191
run: tar -zxvf app.tar.gz
9292

93-
- name: Docker build and publish
94-
uses: docker/build-push-action@v1
93+
- name: Prepare
94+
id: prep
95+
run: |
96+
DOCKER_IMAGE=sakadream/actix-web-rest-api-with-jwt
97+
VERSION=edge
98+
if [[ $GITHUB_REF == refs/tags/* ]]; then
99+
VERSION=${GITHUB_REF#refs/tags/}
100+
elif [[ $GITHUB_REF == refs/heads/* ]]; then
101+
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
102+
elif [[ $GITHUB_REF == refs/pull/* ]]; then
103+
VERSION=pr-${{ github.event.number }}
104+
fi
105+
TAGS="${DOCKER_IMAGE}:${VERSION}"
106+
if [ "${{ github.event_name }}" = "push" ]; then
107+
TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}"
108+
fi
109+
echo ::set-output name=version::${VERSION}
110+
echo ::set-output name=tags::${TAGS}
111+
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
112+
113+
- name: Login to DockerHub
114+
uses: docker/login-action@v1
95115
with:
96116
username: ${{ secrets.DOCKER_USERNAME }}
97117
password: ${{ secrets.DOCKER_PASSWORD }}
98-
repository: sakadream/actix-web-rest-api-with-jwt
99-
add_git_labels: true
100-
tag_with_ref: true
118+
119+
- name: Docker build and publish
120+
uses: docker/build-push-action@v2
121+
with:
122+
context: .
123+
file: ./Dockerfile
124+
tags: ${{ steps.prep.outputs.tags }}
125+
labels: |
126+
org.opencontainers.image.source=${{ github.event.repository.html_url }}
127+
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
128+
org.opencontainers.image.revision=${{ github.sha }}
Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
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+
# NOTE: This Dockerfile is only used for GitHub Actions. For local development, please use 'Dockerfile.local'
2+
# base image
3+
FROM debian:buster-slim
4+
5+
# create app directory
6+
RUN mkdir app
7+
WORKDIR /app
8+
9+
# install libpq
10+
RUN apt-get update; \
11+
apt-get install --no-install-recommends -y libpq5 libsqlite3-0; \
12+
rm -rf /var/lib/apt/lists/*
13+
14+
# copy binary and configuration files
15+
COPY ./actix-web-rest-api-with-jwt .
16+
COPY ./diesel.toml .
17+
COPY ./.env .
18+
COPY ./wait-for-it.sh .
19+
20+
# expose port
21+
EXPOSE 8000
22+
23+
# run the binary
24+
CMD ["./wait-for-it.sh", "db:5432", "--", "/app/actix-web-rest-api-with-jwt"]
Lines changed: 53 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,53 @@
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"]

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)