Skip to content

Commit

Permalink
feat: 무중단 배포를 위한 ecosystem.config.json과 쉘 스크립트 파일 작성
Browse files Browse the repository at this point in the history
- Blue/Green deployment 전략을 사용하기 위해 각 Blue/Green상태의 포트에 맞는 서버 프로세스를 띄운다.
- 새로운 코드가 반영된 서버가 실행되면 Nginx proxy_pass 설정에서 해당 서버에 맞는 포트로 설정해준다.
  • Loading branch information
zzawang committed Dec 1, 2024
1 parent 86e0db1 commit 7858bd8
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 0 deletions.
33 changes: 33 additions & 0 deletions deploy/funch-blue-ecosystem.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"apps": [
{
"name": "chat-server-blue",
"script": "npm",
"args": "run start",
"cwd": "/root/web25-funch/chatServer",
"env": {
"PORT": "7990"
}
},
{
"name": "next-client-blue",
"script": "npm",
"args": "run start",
"cwd": "/root/web25-funch/client",
"env_file": "/root/web25-funch/client/.env",
"env": {
"PORT": "3000"
}
},
{
"name": "api-server-blue",
"script": "npm",
"args": "run start",
"cwd": "/root/web25-funch/applicationServer",
"env_file": "/root/web25-funch/applicationServer/.env",
"env": {
"PORT": "8080"
}
}
]
}
45 changes: 45 additions & 0 deletions deploy/funch-deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

EXIST_BLUE=$(netstat -lntp | grep 3000)

if [ -n "$EXIST_BLUE" ]; then
TARGET_COLOR="green"
NOW_COLOR="blue"
CLIENT_PORT=3001
CHAT_PORT=7991
API_PORT=8081
TARGET_SUFFIX="green"
NOW_SUFFIX="blue"
else
TARGET_COLOR="blue"
NOW_COLOR="green"
CLIENT_PORT=3000
CHAT_PORT=7990
API_PORT=8080
TARGET_SUFFIX="blue"
NOW_SUFFIX="green"
fi

pm2 start ${TARGET_SUFFIX}-ecosystem.config.json

for i in {1..30}; do
if nc -z localhost $CLIENT_PORT &&
nc -z localhost $CHAT_PORT &&
nc -z localhost $API_PORT; then
break
fi
sleep 1
done

sudo sed -i "s/proxy_pass http:\/\/127.0.0.1:[0-9]\+; # Blue\/Green 클라이언트 포트/proxy_pass http:\/\/127.0.0.1:${CLIENT_PORT}; # Blue\/Green 클라이언트 포트/" /etc/nginx/conf.d/www.funch.site.conf
sudo sed -i "s/proxy_pass http:\/\/127.0.0.1:[0-9]\+; # Blue\/Green API 포트/proxy_pass http:\/\/127.0.0.1:${API_PORT}; # Blue\/Green API 포트/" /etc/nginx/conf.d/www.funch.site.conf
sudo sed -i "s/proxy_pass http:\/\/127.0.0.1:[0-9]\+; # Blue\/Green 채팅 포트/proxy_pass http:\/\/127.0.0.1:${CHAT_PORT}; # Blue\/Green 채팅 포트/" /etc/nginx/conf.d/www.funch.site.conf

sudo nginx -s reload

pm2 delete chat-server-${NOW_SUFFIX}
pm2 delete next-client-${NOW_SUFFIX}
pm2 delete api-server-${NOW_SUFFIX}

pm2 save
pm2 clean
33 changes: 33 additions & 0 deletions deploy/funch-green-ecosystem.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"apps": [
{
"name": "chat-server-green",
"script": "npm",
"args": "run start",
"cwd": "/root/web25-funch/chatServer",
"env": {
"PORT": "7991"
}
},
{
"name": "next-client-green",
"script": "npm",
"args": "run start",
"cwd": "/root/web25-funch/client",
"env_file": "/root/web25-funch/client/.env",
"env": {
"PORT": "3001"
}
},
{
"name": "api-server-green",
"script": "npm",
"args": "run start",
"cwd": "/root/web25-funch/applicationServer",
"env_file": "/root/web25-funch/applicationServer/.env",
"env": {
"PORT": "8081"
}
}
]
}
2 changes: 2 additions & 0 deletions deploy/media-deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pm2 kill
pm2 start media-ecosystem.config.json
9 changes: 9 additions & 0 deletions deploy/media-ecosystem.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "media-server",
"script": "npm",
"args": "run start",
"cwd": "/service/web25-funch/mediaServer",
"env": {
"PORT": "1935"
}
}

0 comments on commit 7858bd8

Please sign in to comment.