This repository was archived by the owner on Jan 11, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
94 lines (83 loc) · 3.48 KB
/
deploy.yml
File metadata and controls
94 lines (83 loc) · 3.48 KB
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
name: CD with Gradle
on:
pull_request:
branches:
- main
types:
- closed
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest # ubuntu 최신 버전에서 script를 실행
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: "adopt"
- name: Set Sentry auth token
run: |
echo "export SENTRY_AUTH_TOKEN=${{ secrets.SENTRY_AUTH_TOKEN }}" >> $GITHUB_ENV
- name: Make application.yml
run: |
mkdir -p src/main/resources
echo "${{ secrets.PROPERTIES }}" > src/main/resources/application-prod.yml
- name: Build with Gradle
run: |
chmod +x ./gradlew
./gradlew clean build -x test
- name: Docker build & push to docker repo
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -f Dockerfile -t ${{ secrets.DOCKER_REPO }} .
docker push ${{ secrets.DOCKER_REPO }}
- name: Deploy to server
uses: appleboy/ssh-action@master
id: deploy
with:
host: ${{ secrets.HOST }}
username: ubuntu
key: ${{ secrets.KEY }}
script: |
# Docker 이미지를 최신 상태로 가져오기
sudo docker pull ${{ secrets.DOCKER_REPO }}:latest
# 서버의 현재 환경 확인 (블루 / 그린)
ENV_COLOR=$(curl --silent --fail https://api-spot.store/spot/current-env || echo "none")
if [[ "$ENV_COLOR" == "blue" || "$ENV_COLOR" == "none" ]]; then
# 블루 서버가 실행 중이거나 아무 서버도 돌아가고 있지 않다면 그린 서버를 실행
sudo docker-compose -f docker-compose.yml up -d --no-deps web-green
sleep 75
# 그린 서버가 정상적으로 작동하는지 확인 (예: HTTP 상태 코드 200 확인)
if curl --silent --fail http://localhost:8081; then
echo "Green server is working correctly."
# Nginx를 Green 서버로 전환
sudo sed -i 's/8080/8081/' /etc/nginx/sites-available/api-spot.store
sudo systemctl restart nginx
# 기존 서버 종료
sudo docker-compose -f docker-compose.yml stop web-blue
else
echo "Green server is not responding correctly. Exiting."
exit 1
fi
elif [[ "$ENV_COLOR" == "green" ]]; then
# 그린 서버가 실행 중이면 블루 서버를 실행
sudo docker-compose -f docker-compose.yml up -d --no-deps web-blue
sleep 75
# 블루 서버가 정상적으로 작동하는지 확인
if curl --silent --fail http://localhost:8080; then
echo "Blue server is working correctly."
# Nginx를 Blue 서버로 전환
sudo sed -i 's/8081/8080/' /etc/nginx/sites-available/api-spot.store
sudo systemctl restart nginx
# 기존 서버 종료
sudo docker-compose -f docker-compose.yml stop web-green
else
echo "Blue server is not responding correctly. Exiting."
exit 1
fi
else
echo "Unable to determine current environment, exiting."
exit 1
fi