-
Notifications
You must be signed in to change notification settings - Fork 5
113 lines (90 loc) · 3.9 KB
/
gradle.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
name: Java CI with Gradle
on:
push:
branches: [ "master" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
## create application.yml
- name: make application.yml
run: |
cd ./src/main/resources
## application.yml 파일 생성
touch ./application.yml
## GitHub-Actions 에서 설정한 값을 application.yml 파일에 쓰기
echo "${{ secrets.APPLICATION }}" >> ./application.yml
## application-oauth2.yml 파일 생성
touch ./application-oauth2.yml
## GitHub-Actions 에서 설정한 값을 application-oauth2.yml 파일에 쓰기
echo "${{ secrets.APPLICATION_OAUTH2 }}" >> ./application-oauth2.yml
shell: bash
## build Docker and Push Docker Hub
- name: build with Gradle
run: ./gradlew --exclude-task test
- name: build Docker
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t ${{ secrets.DOCKER_REPO }} .
docker push ${{ secrets.DOCKER_REPO }}:latest
- name: Run scripts in server
uses: appleboy/ssh-action@master
with:
key: ${{ secrets.SSH_KEY }}
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
script: |
sudo docker pull ${{ secrets.DOCKER_REPO }}:latest
echo "실행 중인 도커 확인.."
RUNNING_SERVER=$(sudo docker ps --format 'table{{.Names}}' | grep AA)
if [ -z "${RUNNING_SERVER}"]
then
echo "BB 가 실행중입니다. BB -> AA 서버 교체를 진행합니다.."
START_CONTAINER=AA
TERMINATE_CONTAINER=BB
START_PORT=8080
TERMINATE_PORT=8081
sudo docker run -d -p 8080:8080 --name AA --log-driver=awslogs --log-opt awslogs-region=ap-northeast-2 --log-opt awslogs-group=${{ secrets.LOG_GROUP_NAME }} --log-opt awslogs-stream=${{ secrets.LOG_STREAM_NAME }} ${{ secrets.DOCKER_REPO }}
else
echo "AA가 실행중입니다. AA -> BB 서버 교체를 진행합니다.."
START_CONTAINER=BB
TERMINATE_CONTAINER=AA
START_PORT=8081
TERMINATE_PORT=8080
sudo docker run -d -p 8081:8080 --name BB --log-driver=awslogs --log-opt awslogs-region=ap-northeast-2 --log-opt awslogs-group=${{ secrets.LOG_GROUP_NAME }} --log-opt awslogs-stream=${{ secrets.LOG_STREAM_NAME }} ${{ secrets.DOCKER_REPO }}
fi
for cnt in {1..10}
do
echo "check server start.."
UP=$(curl -s http://127.0.0.1:${START_PORT}/actuator/health | grep 'UP')
if [ -z "${UP}" ]
then
echo "서버가 아직 실행되지 않았습니다.."
else
echo "서버 실행이 확인 되었습니다."
break
fi
echo "10초간 대기 합니다.."
sleep 10
done
if [ $cnt -eq 10 ]
then
echo "deployment failed."
exit 1
fi
echo "server start!"
echo "change nginx server port"
sudo sed -i "s/${TERMINATE_PORT}/${START_PORT}/" /etc/nginx/conf.d/service-url.inc
sudo service nginx restart
sudo docker stop ${TERMINATE_CONTAINER}
sudo docker rm ${TERMINATE_CONTAINER}
sudo docker image prune -f