-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 무중단 배포를 위한 ecosystem.config.json과 쉘 스크립트 파일 작성
- Blue/Green deployment 전략을 사용하기 위해 각 Blue/Green상태의 포트에 맞는 서버 프로세스를 띄운다. - 새로운 코드가 반영된 서버가 실행되면 Nginx proxy_pass 설정에서 해당 서버에 맞는 포트로 설정해준다.
- Loading branch information
Showing
5 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pm2 kill | ||
pm2 start media-ecosystem.config.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |