-
Notifications
You must be signed in to change notification settings - Fork 3
80 lines (69 loc) · 2.39 KB
/
be-cd.yaml
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
name: Backend Deploy
on:
workflow_dispatch:
push:
branches:
- main
paths:
- backend/**
- .github/workflows/be-cd.yaml
- server/docker/docker-compose-be.yaml
- server/docker/docker-compose-db.yaml
concurrency:
group: be
cancel-in-progress: true
jobs:
deploy:
runs-on: ubuntu-latest
environment: prod
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup JDK 21
uses: actions/setup-java@v4
with:
java-version: 21
distribution: temurin
cache: gradle
- name: Build
working-directory: backend
run: |
chmod +x gradlew
./gradlew build -x test
- name: Copy jar
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
source: backend/build/libs/, server/docker
target: ~/${{ github.event.repository.name }}
- name: Setup environment variables
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
script: |
cd ~/${{ github.event.repository.name }}/server/docker
echo "JASYPT_PASSWORD=${{ secrets.JASYPT_PASSWORD }}" > .env
echo "MYSQL_ROOT_PASSWORD=${{ secrets.MYSQL_ROOT_PASSWORD }}" >> .env
- name: Update db and be
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
script: |
cd ~/${{ github.event.repository.name }}/server/docker
docker compose -f docker-compose-be.yaml pull
docker compose -f docker-compose-db.yaml pull
export $(cat .env)
REPO_NAME=$(echo ${{ github.event.repository.name }} | tr '[:upper:]' '[:lower:]')
docker compose -f docker-compose-db.yaml up -d
docker service ls | grep -iw ${REPO_NAME}_be \
&& docker service update --force ${REPO_NAME}_be \
|| docker stack deploy -c docker-compose-be.yaml ${REPO_NAME}
docker image prune -af
docker service inspect ${REPO_NAME}_be --format '{{.UpdateStatus.State}}' \
| grep -qv 'completed' && exit 1