-
Notifications
You must be signed in to change notification settings - Fork 0
168 lines (158 loc) ยท 6.54 KB
/
sinChul.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
name: sinChul
on:
workflow_dispatch:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'adopt'
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
- name: gradlew bootJar
run: ./gradlew bootJar
- name: copy jar to Green server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ec2-user
key: ${{ secrets.SSH_KEY }}
port: 22
source: "./build/libs/*.jar"
target: "/home/ec2-user"
strip_components: 2
- name: Stop existing Green Server
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ec2-user
key: ${{ secrets.SSH_KEY }}
port: 22
script_stop: true
script: |
PID=$(lsof -t -i:8081)
if [ -n "$PID" ]; then
sudo kill -9 $PID
fi
- name: Deploy to Green Server
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ec2-user
key: ${{ secrets.SSH_KEY }}
port: 22
script_stop: true
script: |
export API_KEY="${{ secrets.API_KEY }}"
export JDBC_URL="${{ secrets.JDBC_URL }}"
export JDBC_USERNAME="${{ secrets.JDBC_USERNAME }}"
export JDBC_PASSWORD="${{ secrets.JDBC_PASSWORD }}"
export ENCRYPTION_SECRET_KEY="${{ secrets.ENCRYPTION_SECRET_KEY }}"
export JWT_SECRETKEY="${{ secrets.JWT_SECRETKEY }}"
export API_SERVICE_KEY="${{ secrets.API_SERVICE_KEY }}"
export S3_ACCESS_KEY="${{ secrets.S3_ACCESS_KEY }}"
export S3_NAME="${{ secrets.S3_NAME }}"
export S3_REGION="${{ secrets.S3_REGION }}"
export SECRET_ACCESS_KEY="${{ secrets.SECRET_ACCESS_KEY }}"
export GOOGLE_ACCOUNT="${{ secrets.GOOGLE_ACCOUNT }}"
export GOOGLE_PASSWORD="${{ secrets.GOOGLE_PASSWORD }}"
export GOOGLE_CLIENT_ID="${{ secrets.GOOGLE_CLIENT_ID }}"
export GOOGLE_CLIENT_SECRET="${{ secrets.GOOGLE_CLIENT_SECRET }}"
export GOOGLE_REDIRECT_URI="${{ secrets.GOOGLE_REDIRECT_URI }}"
# Green ์๋ฒ์ ์ ๋ฒ์ ๋ฐฐํฌ
nohup java -jar /home/ec2-user/*.jar --server.port=8081 > nohup_green.out 2>&1 &
- name: Wait for Green Server to start
run: sleep 30 # ์ ํ๋ฆฌ์ผ์ด์
์์ ๋๊ธฐ ์๊ฐ (์ด ๋จ์๋ก ์กฐ์ ๊ฐ๋ฅ)
- name: Verify Green Server
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ec2-user
key: ${{ secrets.SSH_KEY }}
port: 22
script_stop: true
script: |
curl -f http://localhost:8081/aws || exit 1
- name: Update Nginx to point to Green Server
uses: appleboy/[email protected]
with:
host: ${{ secrets.NGINX_HOST }}
username: ec2-user
key: ${{ secrets.SSH_KEY }}
port: 22
script_stop: true
script: |
sudo sed -i 's/proxy_pass http:\/\/app_blue;/proxy_pass http:\/\/app_green;/' /etc/nginx/nginx.conf
if ! sudo systemctl is-active --quiet nginx; then
sudo systemctl start nginx
fi
sudo nginx -t && sudo nginx -s reload
- name: Clean up Blue Server and deploy new version
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ec2-user
key: ${{ secrets.SSH_KEY }}
port: 22
script_stop: true
script: |
PID=$(lsof -t -i:8080)
if [ -n "$PID" ]; then
sudo kill -9 $PID
fi
export API_KEY="${{ secrets.API_KEY }}"
export JDBC_URL="${{ secrets.JDBC_URL }}"
export JDBC_USERNAME="${{ secrets.JDBC_USERNAME }}"
export JDBC_PASSWORD="${{ secrets.JDBC_PASSWORD }}"
export ENCRYPTION_SECRET_KEY="${{ secrets.ENCRYPTION_SECRET_KEY }}"
export JWT_SECRETKEY="${{ secrets.JWT_SECRETKEY }}"
export API_SERVICE_KEY="${{ secrets.API_SERVICE_KEY }}"
export S3_ACCESS_KEY="${{ secrets.S3_ACCESS_KEY }}"
export S3_NAME="${{ secrets.S3_NAME }}"
export S3_REGION="${{ secrets.S3_REGION }}"
export SECRET_ACCESS_KEY="${{ secrets.SECRET_ACCESS_KEY }}"
export GOOGLE_ACCOUNT="${{ secrets.GOOGLE_ACCOUNT }}"
export GOOGLE_PASSWORD="${{ secrets.GOOGLE_PASSWORD }}"
export GOOGLE_CLIENT_ID="${{ secrets.GOOGLE_CLIENT_ID }}"
export GOOGLE_CLIENT_SECRET="${{ secrets.GOOGLE_CLIENT_SECRET }}"
export GOOGLE_REDIRECT_URI="${{ secrets.GOOGLE_REDIRECT_URI }}"
nohup java -jar /home/ec2-user/*.jar --server.port=8080 > nohup_blue.out 2>&1 &
- name: Update Nginx to point to Blue Server
uses: appleboy/[email protected]
with:
host: ${{ secrets.NGINX_HOST }}
username: ec2-user
key: ${{ secrets.SSH_KEY }}
port: 22
script_stop: true
script: |
sudo sed -i 's/proxy_pass http:\/\/app_green;/proxy_pass http:\/\/app_blue;/' /etc/nginx/nginx.conf
if ! sudo systemctl is-active --quiet nginx; then
sudo systemctl start nginx
fi
sudo nginx -t && sudo nginx -s reload
env:
API_KEY: ${{ secrets.API_KEY }}
JDBC_URL: ${{ secrets.JDBC_URL }}
JDBC_USERNAME: ${{ secrets.JDBC_USERNAME }}
JDBC_PASSWORD: ${{ secrets.JDBC_PASSWORD }}
ENCRYPTION_SECRET_KEY: ${{ secrets.ENCRYPTION_SECRET_KEY }}
JWT_SECRETKEY: ${{ secrets.JWT_SECRETKEY }}
API_SERVICE_KEY: ${{ secrets.API_SERVICE_KEY }}
S3_ACCESS_KEY: ${{ secrets.S3_ACCESS_KEY }}
S3_NAME: ${{ secrets.S3_NAME }}
S3_REGION: ${{ secrets.S3_REGION }}
SECRET_ACCESS_KEY: ${{ secrets.SECRET_ACCESS_KEY }}
GOOGLE_ACCOUNT: ${{ secrets.GOOGLE_ACCOUNT }}
GOOGLE_PASSWORD: ${{ secrets.GOOGLE_PASSWORD }}
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }}
GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }}
GOOGLE_REDIRECT_URI: ${{ secrets.GOOGLE_REDIRECT_URI }}