-
Notifications
You must be signed in to change notification settings - Fork 0
120 lines (103 loc) · 3.12 KB
/
prod.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
name: Build, Test and Deploy to Prod
# Trigger the workflow when changes are pushed to the main branch
on:
push:
branches:
- main
env:
SQLX_OFFLINE: true
jobs:
build:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15.2-alpine
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
POSTGRES_DB: postgres
ports:
- 5432:5432
redis:
image: redis:7.0-alpine
ports:
- 6379:6379
steps:
# Checkout code from the repository
- name: Checkout code
uses: actions/checkout@v2
# Cache dependencies to speed up build times
- name: Cache dependencies
uses: actions/cache@v3
with:
path: |
app-service/.cargo
app-service/target/
auth-service/.cargo
auth-service/target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
- name: Build and test app-service code
working-directory: ./app-service
run: |
cargo build --verbose
cargo test --verbose
- name: Build and test auth-service code
working-directory: ./auth-service
run: |
export JWT_SECRET=secret
export DATABASE_URL=postgres://postgres:${{ secrets.POSTGRES_PASSWORD }}@localhost:5432
cargo build --verbose
cargo test --verbose
# Set up Docker Buildx for multi-platform builds
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker images
uses: docker/[email protected]
with:
push: true
files: |
compose.yml
compose.override.yml
set: |
*.cache-from=type=gha
*.cache-to=type=gha,mode=max
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Install sshpass
run: sudo apt-get install sshpass
- name: Copy compose.yml to droplet
run: sshpass -v -p ${{ secrets.DROPLET_PASSWORD }} scp -o StrictHostKeyChecking=no compose.yml root@${{ vars.DROPLET_IP }}:~
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ vars.DROPLET_IP }}
username: root
password: ${{ secrets.DROPLET_PASSWORD }}
script: |
cd ~
export JWT_SECRET=${{ secrets.JWT_SECRET }}
export AUTH_SERVICE_IP=${{ vars.DROPLET_IP }}
export POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }}
docker-compose down
docker-compose pull
docker-compose up -d