Skip to content

Commit

Permalink
๐Ÿš‘ hotfix: ๋ฐฐํฌ ์Šคํฌ๋ฆฝํŠธ ๋™์ž‘ ์˜ค๋ฅ˜ ํ•ด๊ฒฐ
Browse files Browse the repository at this point in the history
  • Loading branch information
jun02160 committed Jan 7, 2024
1 parent 5370c64 commit c8d9a2e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:

blue:
container_name: blue
image: yejunpark1/motivoo-server-8080
image: yejunpark1/motivoo-server
expose:
- 8080
ports:
Expand All @@ -21,7 +21,7 @@ services:

green:
container_name: green
image: yejunpark1/motivoo-server-8081
image: yejunpark1/motivoo-server
expose:
- 8080
ports:
Expand Down
38 changes: 20 additions & 18 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ SERVER_NAME=motivoo-server

DOCKER_PS_OUTPUT=$(docker ps | grep $SERVER_NAME)
RUNNING_CONTAINER_NAME=$(echo "$DOCKER_PS_OUTPUT" | awk '{print $NF}')
RUNNING_SERVER_PORT=$(echo "$RUNNING_CONTAINER_NAME" | awk -F'-' '{print $NF}')

IS_REDIS_ACTIVATE=$(docker ps | grep redis)

Expand All @@ -23,14 +22,19 @@ if [ -z "$IS_REDIS_ACTIVATE" ];then
fi

# ์‹คํ–‰ ์ค‘์ธ ์„œ๋ฒ„ ํฌํŠธ ํ™•์ธ
if [ -z "$RUNNNG_SERVER_PORT" ]; then
echo "[$NOW_TIME] ์‹คํ–‰ ์ค‘์ธ ์„œ๋ฒ„ ํฌํŠธ: ์—†์Œ"
if [ ${RUNNING_CONTAINER_NAME} == "blue" ]; then
echo "[$NOW_TIME] ์‹คํ–‰ ์ค‘์ธ ์„œ๋ฒ„ ํฌํŠธ: blue (:8080)"
RUNNING_SERVER_PORT=8080
elif [ ${RUNNING_CONTAINER_NAME} == "green" ]; then
echo "[$NOW_TIME] ์‹คํ–‰ ์ค‘์ธ ์„œ๋ฒ„ ํฌํŠธ: green (:8081)"
RUNNING_SERVER_PORT=8081
else
echo "[$NOW_TIME] ์‹คํ–‰ ์ค‘์ธ ์„œ๋ฒ„ ํฌํŠธ: $RUNNING_SERVER_PORT"
echo "[$NOW_TIME] ์‹คํ–‰ ์ค‘์ธ ์„œ๋ฒ„ ํฌํŠธ: ์—†์Œ"
fi


# ํ˜„์žฌ ์‹คํ–‰ ์ค‘์ธ ํฌํŠธ ์™ธ ์‹คํ–‰๊ฐ€๋Šฅํ•œ ํฌํŠธ ํ™•์ธ
for iten in "${ALL_PORT[@]}"; do
for item in "${ALL_PORTS[@]}"; do
if [ "$item" != "$RUNNING_SERVER_PORT" ]; then
AVAILABLE_PORT+=("$item")
fi
Expand All @@ -39,15 +43,17 @@ done;
# ์‹คํ–‰ ๊ฐ€๋Šฅํ•œ ํฌํŠธ ์—†์œผ๋ฉด ๋๋‚ด๊ธฐ
if [ ${#AVAILABLE_PORT[@]} -eq 0 ]; then
echo "[$NOW_TIME] ์‹คํ–‰ ๊ฐ€๋Šฅํ•œ ํฌํŠธ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค."
exit 1
# exit 1
fi

# Green Up
if [ $RUNNING_SERVER_PORT -eq 8080 ]; then
if [ $RUNNING_CONTAINER_NAME == "blue" ]; then
echo "[$NOW_TIME] ํ˜„์žฌ ๊ตฌ๋™์ค‘์ธ Port: Blue(:8080)"

echo "[$NOW_TIME] ###### ์Šค์œ„์นญ ######"
echo "[$NOW_TIME] ###### BLUE -> GREEN ######"
CURRENT_SERVER_PORT=8081

echo "[$NOW_TIME] Green ๋„์ปค ์ด๋ฏธ์ง€ pull"
docker-compose pull green
echo "[$NOW_TIME] Green ์ปจํ…Œ์ด๋„ˆ Up (๋นŒ๋“œ & ์‹คํ–‰)"
Expand All @@ -57,7 +63,7 @@ if [ $RUNNING_SERVER_PORT -eq 8080 ]; then
echo "[$NOW_TIME] Green health check ..."
sleep 3

RESPONSE=$(curl -s http://localhost:${RUNNING_SERVER_PORT}${WEB_HEALTH_CHECK_URL})
RESPONSE=$(curl -s http://localhost:8081${WEB_HEALTH_CHECK_URL})
UP_COUNT=$(echo $RESPONSE | grep 'UP' | wc -l)
echo "[$NOW_TIME] Health check ์‘๋‹ต: ${RESPONSE}"

Expand All @@ -79,7 +85,7 @@ if [ $RUNNING_SERVER_PORT -eq 8080 ]; then
echo "----------------------------------------------------------------------"

echo "[$NOW_TIME] Nginx Reload (Port ์Šค์œ„์นญ ์ ์šฉ)"
echo "set \$service_url http://127.0.0.1:${RUNNING_SERVER_PORT};" | sudo tee /etc/nginx/conf.d/service-url.inc
sudo cp /etc/nginx/conf.d/green-url.inc /etc/nginx/conf.d/service-url.inc
sudo nginx -s reload
echo "[$NOW_TIME] Blue ์ปจํ…Œ์ด๋„ˆ ์ค‘๋‹จ"
docker-compose stop blue
Expand All @@ -90,6 +96,8 @@ else

echo "[$NOW_TIME] ###### ์Šค์œ„์นญ ######"
echo "[$NOW_TIME] ###### GREEN -> BLUE ######"
CURRENT_SERVER_PORT=8080

echo "[$NOW_TIME] Blue ๋„์ปค ์ด๋ฏธ์ง€ pull"
docker-compose pull blue
echo "[$NOW_TIME] Blue ์ปจํ…Œ์ด๋„ˆ Up (๋นŒ๋“œ & ์‹คํ–‰)"
Expand All @@ -99,7 +107,7 @@ else
echo "[$NOW_TIME] Blue health check ..."
sleep 3

RESPONSE=$(curl -s http://localhost:${RUNNING_SERVER_PORT}/actuator/health)
RESPONSE=$(curl -s http://localhost:8080${RUNNING_SERVER_PORT}/actuator/health)
UP_COUNT=$(echo $RESPONSE | grep 'UP' | wc -l)
echo "[$NOW_TIME] Health check ์‘๋‹ต: ${RESPONSE}"

Expand All @@ -121,7 +129,7 @@ else
echo "----------------------------------------------------------------------"

echo "[$NOW_TIME] Nginx Reload (Port ์Šค์œ„์นญ ์ ์šฉ)"
echo "set \$service_url http://127.0.0.1:${RUNNING_SERVER_PORT};" | sudo tee /etc/nginx/conf.d/service-url.inc
sudo cp /etc/nginx/conf.d/blue-url.inc /etc/nginx/conf.d/service-url.inc
sudo nginx -s reload
echo "[$NOW_TIME] Green ์ปจํ…Œ์ด๋„ˆ ์ค‘๋‹จ"
docker-compose stop green
Expand All @@ -130,7 +138,7 @@ fi
echo "----------------------------------------------------------------------"

# Nginx๋ฅผ ํ†ตํ•ด์„œ ์„œ๋ฒ„์— ์ ‘๊ทผ ๊ฐ€๋Šฅํ•œ์ง€ ํ™•์ธ
RESPONSE=$(curl -s http://localhost:${RUNNING_SERVER_PORT}/actuator/health)
RESPONSE=$(curl -s http://localhost:${CURRENT_SERVER_PORT}${WEB_HEALTH_CHECK_URL})
UP_COUNT=$(echo $RESPONSE | grep 'UP' | wc -l)
echo "[$NOW_TIME] Health check ์‘๋‹ต: ${RESPONSE}"

Expand All @@ -143,9 +151,3 @@ else
exit 1
fi

# ์Šค์œ„์นญ ์ด์ „์˜ ์„œ๋ฒ„ ์žˆ๋‹ค๋ฉด ์ค‘๋‹จ
if [ -n "$RUNNING_SERVER_PORT" ]; then
echo "> ๊ธฐ์กด ${RUNNING_SERVER_PORT}ํฌํŠธ ์„œ๋ฒ„ ์ค‘๋‹จ"
sudo docker rm -f ${SERVER_NAME}-${RUNNING_SERVER_PORT}
fi

0 comments on commit c8d9a2e

Please sign in to comment.