Skip to content

Commit 572b489

Browse files
authored
Merge pull request #15 from SakaDream/apply-github-actions
Apply GitHub actions
2 parents 4d5aa32 + f0318d7 commit 572b489

File tree

7 files changed

+374
-2
lines changed

7 files changed

+374
-2
lines changed
Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
name: Cross-platform CICD
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
cicd-linux:
7+
name: CICD Linux
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout sources
11+
uses: actions/checkout@v2
12+
13+
- name: Install stable toolchain
14+
uses: actions-rs/toolchain@v1
15+
with:
16+
toolchain: stable
17+
18+
- name: Get temporary secret key
19+
shell: sh
20+
run: |
21+
mv src/secret.key.sample src/secret.key
22+
23+
- name: Cache cargo registry
24+
uses: actions/cache@v1
25+
with:
26+
path: ~/.cargo/registry
27+
key: ${{ runner.os }}-registry-${{ hashFiles('**/Cargo.lock') }}
28+
restore-keys: |
29+
${{ runner.os }}-registry-
30+
${{ runner.os }}-
31+
32+
- name: Cache cargo index
33+
uses: actions/cache@v1
34+
with:
35+
path: ~/.cargo/git
36+
key: ${{ runner.os }}-index-${{ hashFiles('**/Cargo.lock') }}
37+
restore-keys: |
38+
${{ runner.os }}-index-
39+
${{ runner.os }}-
40+
41+
- name: Cache cargo build
42+
uses: actions/cache@v1
43+
with:
44+
path: target
45+
key: ${{ runner.os }}-build-${{ hashFiles('**/Cargo.lock') }}
46+
restore-keys: |
47+
${{ runner.os }}-build-
48+
${{ runner.os }}-
49+
50+
- name: Run cargo check
51+
uses: actions-rs/cargo@v1
52+
with:
53+
command: check
54+
args: --release
55+
56+
- name: Run cargo fmt
57+
uses: actions-rs/cargo@v1
58+
continue-on-error: true
59+
with:
60+
command: fmt
61+
args: --all -- --check
62+
63+
- name: Run cargo clippy
64+
uses: actions-rs/cargo@v1
65+
continue-on-error: true
66+
with:
67+
command: clippy
68+
args: -- -D warnings
69+
70+
- name: Run cargo build
71+
uses: actions-rs/cargo@v1
72+
with:
73+
command: build
74+
args: --release
75+
76+
cicd-windows:
77+
name: CICD Windows
78+
runs-on: windows-latest
79+
steps:
80+
- name: Checkout sources
81+
uses: actions/checkout@v2
82+
83+
- name: Install stable toolchain
84+
uses: actions-rs/toolchain@v1
85+
with:
86+
toolchain: stable
87+
88+
- name: Download libpq.lib
89+
run: |
90+
New-Item -Path "." -Name "libs" -ItemType "directory"
91+
Invoke-WebRequest -Uri https://sakadream.me/cloud/index.php/s/JXnJvyjifGBPuR2/download -OutFile libs\libpq.lib
92+
93+
- name: Get temporary secret key
94+
shell: cmd
95+
run: ren src\secret.key.sample secret.key
96+
97+
- name: Cache cargo registry
98+
uses: actions/cache@v1
99+
with:
100+
path: ~/.cargo/registry
101+
key: ${{ runner.os }}-registry-${{ hashFiles('**/Cargo.lock') }}
102+
restore-keys: |
103+
${{ runner.os }}-registry-
104+
${{ runner.os }}-
105+
106+
- name: Cache cargo index
107+
uses: actions/cache@v1
108+
with:
109+
path: ~/.cargo/git
110+
key: ${{ runner.os }}-index-${{ hashFiles('**/Cargo.lock') }}
111+
restore-keys: |
112+
${{ runner.os }}-index-
113+
${{ runner.os }}-
114+
115+
- name: Cache cargo build
116+
uses: actions/cache@v1
117+
with:
118+
path: target
119+
key: ${{ runner.os }}-build-${{ hashFiles('**/Cargo.lock') }}
120+
restore-keys: |
121+
${{ runner.os }}-build-
122+
${{ runner.os }}-
123+
124+
- name: Run cargo check
125+
uses: actions-rs/cargo@v1
126+
with:
127+
command: check
128+
args: --release
129+
env:
130+
RUSTFLAGS: -L D:\a\actix-web-rest-api-with-jwt\actix-web-rest-api-with-jwt\libs
131+
132+
- name: Run cargo fmt
133+
uses: actions-rs/cargo@v1
134+
continue-on-error: true
135+
with:
136+
command: fmt
137+
args: --all -- --check
138+
139+
- name: Run cargo clippy
140+
uses: actions-rs/cargo@v1
141+
continue-on-error: true
142+
with:
143+
command: clippy
144+
args: -- -D warnings
145+
146+
- name: Run cargo build
147+
uses: actions-rs/cargo@v1
148+
with:
149+
command: build
150+
args: --release
151+
env:
152+
RUSTFLAGS: -L D:\a\actix-web-rest-api-with-jwt\actix-web-rest-api-with-jwt\libs
153+
154+
cicd-macos:
155+
name: CICD macOS
156+
runs-on: macos-latest
157+
steps:
158+
- name: Checkout sources
159+
uses: actions/checkout@v2
160+
161+
- name: Install stable toolchain
162+
uses: actions-rs/toolchain@v1
163+
with:
164+
toolchain: stable
165+
166+
- name: Get temporary secret key
167+
shell: sh
168+
run: |
169+
mv src/secret.key.sample src/secret.key
170+
171+
- name: Cache cargo registry
172+
uses: actions/cache@v1
173+
with:
174+
path: ~/.cargo/registry
175+
key: ${{ runner.os }}-registry-${{ hashFiles('**/Cargo.lock') }}
176+
restore-keys: |
177+
${{ runner.os }}-registry-
178+
${{ runner.os }}-
179+
180+
- name: Cache cargo index
181+
uses: actions/cache@v1
182+
with:
183+
path: ~/.cargo/git
184+
key: ${{ runner.os }}-index-${{ hashFiles('**/Cargo.lock') }}
185+
restore-keys: |
186+
${{ runner.os }}-index-
187+
${{ runner.os }}-
188+
189+
- name: Cache cargo build
190+
uses: actions/cache@v1
191+
with:
192+
path: target
193+
key: ${{ runner.os }}-build-${{ hashFiles('**/Cargo.lock') }}
194+
restore-keys: |
195+
${{ runner.os }}-build-
196+
${{ runner.os }}-
197+
198+
- name: Run cargo check
199+
uses: actions-rs/cargo@v1
200+
with:
201+
command: check
202+
args: --release
203+
204+
- name: Run cargo fmt
205+
uses: actions-rs/cargo@v1
206+
continue-on-error: true
207+
with:
208+
command: fmt
209+
args: --all -- --check
210+
211+
- name: Run cargo clippy
212+
uses: actions-rs/cargo@v1
213+
continue-on-error: true
214+
with:
215+
command: clippy
216+
args: -- -D warnings
217+
218+
- name: Run cargo build
219+
uses: actions-rs/cargo@v1
220+
with:
221+
command: build
222+
args: --release
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: Docker CICD
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
cicd-linux-docker:
13+
name: CICD Linux for Docker
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout sources
17+
uses: actions/checkout@v2
18+
19+
- name: Install stable toolchain
20+
uses: actions-rs/toolchain@v1
21+
with:
22+
toolchain: stable
23+
profile: minimal
24+
override: true
25+
26+
- name: Generate secret key
27+
run: head -c16 /dev/urandom > src/secret.key
28+
29+
- name: Cache cargo registry
30+
uses: actions/cache@v1
31+
with:
32+
path: ~/.cargo/registry
33+
key: docker-registry-${{ hashFiles('**/Cargo.lock') }}
34+
restore-keys: |
35+
docker-registry-
36+
docker-
37+
38+
- name: Cache cargo index
39+
uses: actions/cache@v1
40+
with:
41+
path: ~/.cargo/git
42+
key: docker-index-${{ hashFiles('**/Cargo.lock') }}
43+
restore-keys: |
44+
docker-index-
45+
docker-
46+
47+
- name: Cache cargo build
48+
uses: actions/cache@v1
49+
with:
50+
path: target
51+
key: docker-build-${{ hashFiles('**/Cargo.lock') }}
52+
restore-keys: |
53+
docker-build-
54+
docker-
55+
56+
- name: Run cargo build
57+
uses: actions-rs/cargo@v1
58+
with:
59+
command: build
60+
args: --release
61+
62+
- name: Copy neccessary files and zip
63+
run: |
64+
mkdir app
65+
cp target/release/actix-web-rest-api-with-jwt app/actix-web-rest-api-with-jwt
66+
cp diesel.toml app/diesel.toml
67+
cp docker/prod/Dockerfile app/Dockerfile
68+
cd app
69+
touch .env
70+
tar -czvf ../app.tar.gz .
71+
cd ..
72+
73+
- name: Upload app archive for Docker job
74+
uses: actions/upload-artifact@v1
75+
with:
76+
name: artifact-linux-docker
77+
path: app.tar.gz
78+
79+
80+
cicd-docker:
81+
name: CICD Docker
82+
runs-on: ubuntu-latest
83+
needs: cicd-linux-docker
84+
steps:
85+
- name: Download app archive
86+
uses: actions/download-artifact@v2
87+
with:
88+
name: artifact-linux-docker
89+
90+
- name: Extract app archive
91+
run: tar -zxvf app.tar.gz
92+
93+
- name: Docker build and publish
94+
uses: docker/build-push-action@v1
95+
with:
96+
username: ${{ secrets.DOCKER_USERNAME }}
97+
password: ${{ secrets.DOCKER_PASSWORD }}
98+
repository: sakadream/actix-web-rest-api-with-jwt
99+
add-git-labels: true
100+
tag_with_ref: true

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Actix-web REST API with JWT
22

3+
![Cross-platform CICD](https://github.com/SakaDream/actix-web-rest-api-with-jwt/workflows/Cross-platform%20CICD/badge.svg)
4+
35
A simple CRUD backend app using Actix-web, Diesel and JWT
46

57
## Require
@@ -24,7 +26,8 @@ Or using [Docker](https://www.docker.com/)
2426

2527
### Docker
2628

27-
- Enter into project directory and run `docker-compose up`
29+
- Enter into project directory
30+
- Run `docker-compose -f docker-compose.local.yml up` for local environment or `docker-compose -f docker-compose.prod.yml up` for production environment
2831
- Enjoy! 😄
2932

3033
## APIs

docker-compose.local.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
container_name: address_book_be
13+
build:
14+
context: .
15+
dockerfile: docker/local/Dockerfile
16+
restart: always
17+
ports:
18+
- "8000:8000"
19+
environment:
20+
- APP_HOST=0.0.0.0
21+
- APP_PORT=8000
22+
- DATABASE_URL=postgres://postgres:postgres@db/postgres
23+
depends_on:
24+
- db

docker-compose.yml renamed to docker-compose.prod.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ services:
99
environment:
1010
- POSTGRES_PASSWORD=postgres
1111
app:
12-
build: .
12+
container_name: address_book_be
13+
image: sakadream/actix-web-rest-api-with-jwt
1314
restart: always
1415
ports:
1516
- "8000:8000"
File renamed without changes.

0 commit comments

Comments
 (0)