-
Notifications
You must be signed in to change notification settings - Fork 1
/
bluegreen-dev.sh
53 lines (48 loc) · 1.79 KB
/
bluegreen-dev.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
EXIST_BLUE=$(docker compose -p keyneez-blue -f ./docker-compose/docker-compose-dev.blue.yml ps | grep Up)
if [ -z "$EXIST_BLUE" ]; then
docker compose -p keyneez-blue -f ./docker-compose/docker-compose-dev.blue.yml pull &&
docker compose -p keyneez-blue -f ./docker-compose/docker-compose-dev.blue.yml up -d
BEFORE_COLOR="green"
AFTER_COLOR="blue"
BEFORE_PORT="4001"
AFTER_PORT="4000"
echo "현재 green container 실행 중.. blue 컨테이너 실행 시작 "
else
docker compose -p keyneez-green -f ./docker-compose/docker-compose-dev.green.yml pull &&
docker compose -p keyneez-green -f ./docker-compose/docker-compose-dev.green.yml up -d
BEFORE_COLOR="blue"
AFTER_COLOR="green"
BEFORE_PORT="4000"
AFTER_PORT="4001"
echo "현재 blue 컨테이너 실행 중 ... green 컨테이너 실행 시작"
fi
echo "------------------------------docker health check -----------------------"
docker ps -a
echo "${AFTER_COLOR} 컨테이너 구동 준비 완료, server port = ${AFTER_PORT}"
for cnt in 1 2 3 4 5 6 7 8 9 10
do
echo "서버 응답 확인중 .. (${cnt}/10)"
UP=$(curl -s http://localhost:${AFTER_PORT}/api/health |grep 'ok')
echo $UP
if [ -z "${UP}" ]; then
sleep 5
continue
else
break
fi
done
echo "count : $cnt"
if [ $cnt -eq 10 ];
then
docker ps -a
docker logs --tail 30 keyneez-${AFTER_COLOR}
echo "${AFTER_COLOR} 서버가 정상적으로 구동 되지 않았습니다"
exit 1
fi
sudo sed -i "s/${BEFORE_PORT}/${AFTER_PORT}/" /etc/nginx/conf.d/service-url.inc
sudo nginx -s reload
echo "DEPLOY END!! new Container ${AFTER_COLOR} 서버 러닝 시작"
echo "기존 ${BEFORE_COLOR} 컨테이너 종료 "
docker compose -p keyneez-${BEFORE_COLOR} -f ./docker-compose/docker-compose-dev.${BEFORE_COLOR}.yml down
echo "image clean Up"
docker rmi -f $(docker images -f "dangling=true" -q) || true