-
Notifications
You must be signed in to change notification settings - Fork 3
151 lines (124 loc) · 5.63 KB
/
backend-cd-workflow-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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
name: deploy
on:
push:
branches: [ "release/backend" ]
paths:
- "backend/**"
jobs:
build-a:
runs-on: self-hosted-prod-a
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: "17"
distribution: "corretto"
- name: create-json
uses: jsdaniell/[email protected]
with:
name: "firebase-friendogly-private-key.json"
json: ${{ secrets.FIREBASE_FRIENDOGLY_PRIVATE_KEY }}
dir: './backend/src/main/resources/'
- name: Grant execute permission for gradlew
working-directory: ./backend
run: chmod +x gradlew
- name: Build project using Gradle
working-directory: ./backend
run: ./gradlew build
deploy-a:
needs: build-a
runs-on: self-hosted-prod-a
steps:
- name: Change permission
run: |
sudo chown -R ubuntu:ubuntu /home/ubuntu/actions-runner/_work/2024-friendogly
- name: Find Java Application PID And Kill PID
id: find_pid
run: |
sudo pgrep -f friendogly-0.0.1-SNAPSHOT.jar | xargs sudo kill -9 | true
- name: Check if WAS is running on port 8080 after stop
run: |
PID=$(lsof -t -i:8080 || true)
if [ -n "$PID" ]; then
echo "Server is still running with PID: $PID"
exit 1
else
echo "Server successfully stopped."
fi
- name: Start server
run: |
cd backend/build/libs
echo "File creation time(KR-09:00):"
ls -l --time=ctime friendogly-0.0.1-SNAPSHOT.jar
sudo nohup java -jar friendogly-0.0.1-SNAPSHOT.jar --spring.profiles.active=prod --jwt.secret-key=${{ secrets.JWT_SECRET_KEY }} --jwt.access-expiration-time=${{ secrets.JWT_ACCESS_EXPIRATION_TIME }} --jwt.refresh-expiration-time=${{ secrets.JWT_REFRESH_EXPIRATION_TIME }} --kakao.admin-key=${{ secrets.KAKAO_ADMIN_KEY }} --spring.datasource.writer.hikari.jdbc-url=${{ secrets.MYSQL_RDS_WRITER_URL }} --spring.datasource.writer.hikari.username=${{ secrets.MYSQL_RDS_USERNAME }} --spring.datasource.writer.hikari.password=${{ secrets.MYSQL_RDS_PASSWORD }} --spring.datasource.reader.hikari.jdbc-url=${{ secrets.MYSQL_RDS_READER_URL }} --spring.datasource.reader.hikari.username=${{ secrets.MYSQL_RDS_USERNAME }} --spring.datasource.reader.hikari.password=${{ secrets.MYSQL_PASSWORD }} &
echo "start backend server"
- name: Wait until WAS being started
run: |
URL="http://localhost:8080/healthchecktestapi"
wait_time=0
while true; do
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "$URL" | true)
if [[ $HTTP_STATUS =~ ^[0-9]+$ ]] && [ "$HTTP_STATUS" -eq 404 ]; then
echo "WAS has started"
break
fi
if [ $wait_time -ge 120 ]; then
echo "WAS has not started, waited too long"
break
fi
echo "WAS has not yet started"
sleep 3
wait_time=$((wait_time + 3))
done
build-b:
needs: deploy-a
runs-on: self-hosted-prod-b
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: "17"
distribution: "corretto"
- name: create-json
uses: jsdaniell/[email protected]
with:
name: "firebase-friendogly-private-key.json"
json: ${{ secrets.FIREBASE_FRIENDOGLY_PRIVATE_KEY }}
dir: './backend/src/main/resources/'
- name: Grant execute permission for gradlew
working-directory: ./backend
run: chmod +x gradlew
- name: Build project using Gradle
working-directory: ./backend
run: ./gradlew build
deploy-b:
needs: build-b
runs-on: self-hosted-prod-b
steps:
- name: Change permission
run: |
sudo chown -R ubuntu:ubuntu /home/ubuntu/actions-runner/_work/2024-friendogly
- name: Find Java Application PID And Kill PID
id: find_pid
run: |
sudo pgrep -f friendogly-0.0.1-SNAPSHOT.jar | xargs sudo kill -9 | true
- name: Check if WAS is running on port 8080 after stop
run: |
PID=$(lsof -t -i:8080 || true)
if [ -n "$PID" ]; then
echo "Server is still running with PID: $PID"
exit 1
else
echo "Server successfully stopped."
fi
- name: Start server
run: |
cd backend/build/libs
echo "File creation time(KR-09:00):"
ls -l --time=ctime friendogly-0.0.1-SNAPSHOT.jar
sudo nohup java -jar friendogly-0.0.1-SNAPSHOT.jar --spring.profiles.active=prod --jwt.secret-key=${{ secrets.JWT_SECRET_KEY }} --jwt.access-expiration-time=${{ secrets.JWT_ACCESS_EXPIRATION_TIME }} --jwt.refresh-expiration-time=${{ secrets.JWT_REFRESH_EXPIRATION_TIME }} --kakao.admin-key=${{ secrets.KAKAO_ADMIN_KEY }} --spring.datasource.writer.hikari.jdbc-url=${{ secrets.MYSQL_RDS_WRITER_URL }} --spring.datasource.writer.hikari.username=${{ secrets.MYSQL_RDS_USERNAME }} --spring.datasource.writer.hikari.password=${{ secrets.MYSQL_RDS_PASSWORD }} --spring.datasource.reader.hikari.jdbc-url=${{ secrets.MYSQL_RDS_READER_URL }} --spring.datasource.reader.hikari.username=${{ secrets.MYSQL_RDS_USERNAME }} --spring.datasource.reader.hikari.password=${{ secrets.MYSQL_PASSWORD }} &
echo "start backend server"