forked from FONE1light/fone-backend-jdsl
-
Notifications
You must be signed in to change notification settings - Fork 1
85 lines (76 loc) · 2.62 KB
/
deploy-api-to-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
name: Deploy API To Prod
on:
release:
types: [ published ]
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set Up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'
- name: Grant Execute Permission For Gradlew
run: chmod +x gradlew
- name: Make Prod1 Yml
run: |
cd ./server/src/main/resources
touch ./application-prod1.yml
echo "${{ secrets.PROPERTIES_PROD1 }}" > ./application-prod1.yml
shell: bash
- name: Make Prod2 Yml
run: |
cd ./server/src/main/resources
touch ./application-prod2.yml
echo "${{ secrets.PROPERTIES_PROD2 }}" > ./application-prod2.yml
- name: Build With Gradle
run: ./gradlew :server:bootJar -x test
- name: Docker Build And Push
run: |
docker login -u ${{ secrets.USERNAME }} -p ${{ secrets.PASSWORD }}
docker build -f docker/api.Dockerfile -t fone-api .
docker tag fone-api sinkyoungdeok/fone-api
docker push sinkyoungdeok/fone-api
- name: Deploy Prod
uses: appleboy/[email protected]
with:
key: ${{ secrets.SSH_KEY }}
host: ${{ secrets.HOST_NAME }}
username: ubuntu
port: 22
script: |
docker login -u ${{ secrets.USERNAME }} -p ${{ secrets.PASSWORD }}
docker pull sinkyoungdeok/fone-api
echo "> 구동중인 Profile 확인"
CURRENT_PROFILE=$(curl -s http://localhost/profile)
echo "> $CURRENT_PROFILE"
echo "> profile setting"
if [ "$CURRENT_PROFILE" == "prod1" ]
then
IDLE_PROFILE=prod2
IDLE_PORT=8082
elif [ "$CURRENT_PROFILE" == "prod2" ]
then
IDLE_PROFILE=prod1
IDLE_PORT=8081
else
echo "> 일치하는 Profile이 없음."
IDLE_PROFILE=prod1
IDLE_PORT=8081
fi
echo "> 배포"
if [ "$IDLE_PROFILE" == "prod1" ]
then
docker-compose build fone-api-1
docker-compose up -d fone-api-1
else
docker-compose build fone-api-2
docker-compose up -d fone-api-2
fi
sleep 60
echo "> Change Nginx Proxy Port"
echo "set \$service_url http://127.0.0.1:${IDLE_PORT};" |sudo tee /etc/nginx/conf.d/service-url.inc
echo "> Nginx Reload"
sudo service nginx reload