Skip to content

Commit

Permalink
Update deploy.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
qogustj authored Mar 25, 2024
1 parent 81b0f4f commit 46d6caa
Showing 1 changed file with 30 additions and 38 deletions.
68 changes: 30 additions & 38 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,59 +1,51 @@
#!/bin/bash

IS_GREEN=$(docker ps | grep green) # 현재 실행중인 App이 blue인지 확인합니다.
IS_GREEN_EXIST=$(docker ps | grep green)
DEFAULT_CONF=" /etc/nginx/nginx.conf"

if [ -z $IS_GREEN ];then # blue라면

# blue가 실행 중이면 green을 up합니다.
if [ -z $IS_GREEN_EXIST ];then
echo "### BLUE => GREEN ####"

echo "1. get green image"
docker-compose pull green # green으로 이미지를 내려받습니다.

echo "2. green container up"
docker-compose up -d green # green 컨테이너 실행

echo ">>> green image를 pull합니다."
docker-compose pull green
echo ">>> green container를 up합니다."
docker-compose up -d green
while [ 1 = 1 ]; do
echo "3. green health check..."
sleep 3

REQUEST=$(curl http://127.0.0.1:8082) # green으로 request
if [ -n "$REQUEST" ]; then # 서비스 가능하면 health check 중지
echo "health check success"
break ;
fi
echo ">>> green health check 중..."
sleep 3
REQUEST=$(curl http://127.0.0.1:8082)
if [ -n "$REQUEST" ]; then
echo ">>> 🍃 health check success !"
break;
fi
done;

echo "4. reload nginx"
sleep 3
echo ">>> nginx를 다시 실행 합니다."
sudo cp /etc/nginx/nginx.green.conf /etc/nginx/nginx.conf
sudo nginx -s reload

echo "5. blue container down"
echo ">>> blue container를 down합니다."
docker-compose stop blue

# green이 실행 중이면 blue를 up합니다.
else
echo "### GREEN => BLUE ###"

echo "1. get blue image"
echo ">>> blue image를 pull합니다."
docker-compose pull blue

echo "2. blue container up"
echo ">>> blue container up합니다."
docker-compose up -d blue

while [ 1 = 1 ]; do
echo "3. blue health check..."
echo ">>> blue health check..."
sleep 3
REQUEST=$(curl http://127.0.0.1:8081) # blue로 request

if [ -n "$REQUEST" ]; then # 서비스 가능하면 health check 중지
echo "health check success"
break ;
REQUEST=$(curl http://127.0.0.1:8081)
if [ -n "$REQUEST" ]; then
echo ">>> 🍃 health check success !"
break;
fi
done;

echo "4. reload nginx"
sleep 3
echo ">>> nginx를 다시 실행 합니다."
sudo cp /etc/nginx/nginx.blue.conf /etc/nginx/nginx.conf
sudo nginx -s reload

echo "5. green container down"
echo ">>> green container를 down합니다."
docker-compose stop green
fi
fi

0 comments on commit 46d6caa

Please sign in to comment.