Skip to content

Commit

Permalink
infra: 무중단배포 스크립트 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
sosow0212 committed Oct 17, 2023
1 parent 209b6fb commit 211291a
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 7 deletions.
25 changes: 20 additions & 5 deletions .github/workflows/backend-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,18 @@ jobs:

script: |
sudo docker pull woowacarffeine/backend:latest
sudo docker stop backend || true
sudo docker container prune -f
if sudo docker ps | grep ":8080"; then
BEFORE_PORT=8080
NEW_PORT=8081
NEW_ACTUATOR_PORT=8088
else
BEFORE_PORT=8081
NEW_PORT=8080
NEW_ACTUATOR_PORT=8089
fi
sudo docker run -d -p 8080:8080 -p 8088:8088 \
sudo docker run -d -p $NEW_PORT:8080 -p $NEW_ACTUATOR_PORT:8088 \
-e "SPRING_PROFILE=prod" \
-e "ENCRYPT_KEY=${{secrets.JASYPT_KEY}}" \
-e "DATABASE_USERNAME=${{secrets.DATABASE_USERNAME}}" \
Expand All @@ -93,5 +101,12 @@ jobs:
-e "SLACK_WEBHOOK_URL=${{secrets.SLACK_WEBHOOK_URL}}" \
--name backend \
woowacarffeine/backend:latest
sudo docker image prune -a -f
- name: Execute bluegreen.sh
run: ./bluegreen.sh
env:
NEW_PORT: $NEW_PORT
NEW_ACTUATOR_PORT: $NEW_ACTUATOR_PORT
BEFORE_PORT: $BEFORE_PORT
shell: bash
2 changes: 1 addition & 1 deletion backend/src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ spring:
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect

initialize-city:
enabled: true
enabled: false

initialize-charge:
enabled: false
Expand Down
3 changes: 2 additions & 1 deletion backend/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
server:
port: 8080
shutdown: graceful
servlet:
context-path: /api
tomcat:
Expand Down Expand Up @@ -36,7 +37,7 @@ management:
endpoints:
web:
exposure:
include: prometheus
include: prometheus, health

jwt:
secret: ENC(t6iKCv1Nj+ygRxG2oZCw3l4v9y0ALS2GfQwYIKvO0tRuPzFp4UYRZYfBFdBW+xQl77rOLbfIPJ13tys/tXj3Qw==)
Expand Down
42 changes: 42 additions & 0 deletions shellscript/bluegreen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

BEFORE_PORT="$BEFORE_PORT"
NEW_PORT="$NEW_PORT"
NEW_ACTUATOR_PORT="$NEW_ACTUATOR_PORT"

echo "기존 포트 : $BEFORE_PORT"
echo "새로운 포트: $NEW_PORT"
echo "새로운 ACTUATOR_PORT: $NEW_ACTUATOR_PORT"

count=0
for count in {0..20}
do
echo "서버 상태 확인(${count}/20)";

UP=$(curl -s http://127.0.0.1:${NEW_ACTUATOR_PORT}/actuator/health-check)

if [ "${UP}" != '{"status":"up"}' ]
then
sleep 10
continue
else
break
fi
done

if [ $count -eq 20 ]
then
echo "새로운 서버 배포를 실패했습니다."
exit 1
fi

export BACKEND_PORT=$NEW_PORT
envsubst '${BACKEND_PORT}' < backend.template > backend.conf
sudo mv backend.conf /etc/nginx/conf.d/
sudo nginx -s reload

if sudo docker ps | grep ${BEFORE_PORT}; then
sudo docker stop $(docker ps -q --filter "expose=${BEFORE_PORT}")
fi

sudo docker container prune -f

0 comments on commit 211291a

Please sign in to comment.