-
Notifications
You must be signed in to change notification settings - Fork 6
130 lines (103 loc) · 4.16 KB
/
backend-prod-cd.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
name: backend-prod-cd
on:
pull_request:
branches: [ "main" ]
types: [closed]
jobs:
build:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/gradle-build-action@v3
with:
gradle-version: 8.8
- name: Grant execute permission for gradlew
run: chmod +x backend/bang-ggood/gradlew
- name: Write application.yml
env:
APPLICATION_YML: ${{ secrets.APPLICATION_YML }}
APPLICATION_PROD_YML: ${{ secrets.APPLICATION_PROD_YML }}
APPLICATION_TEST_YML: ${{ secrets.APPLICATION_TEST_YML }}
APPLICATION_READ_WRITE_TEST_YML: ${{ secrets.APPLICATION_READ_WRITE_TEST_YML }}
run: |
echo "${APPLICATION_YML}" > backend/bang-ggood/src/main/resources/application.yml
echo "${APPLICATION_PROD_YML}" > backend/bang-ggood/src/main/resources/application-prod.yml
echo "${APPLICATION_TEST_YML}" > backend/bang-ggood/src/test/resources/application-test.yml
echo "${APPLICATION_READ_WRITE_TEST_YML}" > backend/bang-ggood/src/test/resources/application-read-write-test.yml
- name: Build with Gradle
run: ./gradlew clean build
working-directory: backend/bang-ggood
- name: Upload build artifact
uses: actions/upload-artifact@v3
with:
working-directory: backend/bang-ggood
name: bang-ggood-be-develop-jar
path: ./**/*.jar
deploy1:
needs: build
runs-on: bang-ggood-prod1
steps:
- name: change permission
run: sudo chown -R ubuntu:ubuntu /home/ubuntu/actions-runner/_work/2024-bang-ggood
- name: Download build artifact
uses: actions/download-artifact@v3
with:
name: bang-ggood-be-develop-jar
- name: Create unhealth_flag file
run: echo "unhealth" | sudo tee /etc/nginx/sites-available/unhealth_flag.txt > /dev/null
- name: Sleep for 30 seconds to be unhealthy
run: sleep 30
- name: Turn off the server 8080 if runs
run: sudo fuser -k -n tcp 8080 || true
- name: Start server
run: sudo nohup java -jar -Dspring.profiles.active=prod -Duser.timezone=Asia/Seoul ./backend/bang-ggood/build/libs/*SNAPSHOT.jar > /home/ubuntu/actions-runner/server.log 2>&1 &
- name: Delete unhealth_flag file
run: sudo rm /etc/nginx/sites-available/unhealth_flag.txt
- name: Sleep for 30 seconds to be healthy
run: sleep 30
- name: Health check
run: |
for i in {1..2}; do
RESPONSE=$(curl -s -w "%{http_code}" -o /dev/null http://localhost:8080/health-check)
echo "Response: $RESPONSE"
if [ "$RESPONSE" -eq 200 ]; then
echo "Health check passed"
exit 0
fi
echo "Waiting for server to be healthy..."
sleep 10
done
echo "Health check failed"
exit 1
deploy2:
needs: deploy1
runs-on: bang-ggood-prod2
steps:
- name: change permission
run: sudo chown -R ubuntu:ubuntu /home/ubuntu/actions-runner/_work/2024-bang-ggood
- name: Download build artifact
uses: actions/download-artifact@v3
with:
name: bang-ggood-be-develop-jar
- name: Create unhealth_flag file
run: echo "unhealth" | sudo tee /etc/nginx/sites-available/unhealth_flag.txt > /dev/null
- name: Sleep for 30 seconds to be unhealthy
run: sleep 30
- name: Turn off the server 8080 if runs
run: sudo fuser -k -n tcp 8080 || true
- name: Start server
run: sudo nohup java -jar -Dspring.profiles.active=prod -Duser.timezone=Asia/Seoul ./backend/bang-ggood/build/libs/*SNAPSHOT.jar > /home/ubuntu/actions-runner/server.log 2>&1 &
- name: Delete unhealth_flag file
run: sudo rm /etc/nginx/sites-available/unhealth_flag.txt
- name: Sleep for 30 seconds to be healthy
run: sleep 30