-
Notifications
You must be signed in to change notification settings - Fork 2
/
deploy-dev.sh
101 lines (75 loc) Β· 2.5 KB
/
deploy-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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
if [ $(docker ps | grep -c "nginx-dev") -eq 0 ]; then
echo "Starting nginx-dev..."
docker-compose up -d nginx-dev
else
echo "-------------------------------------------"
echo "nginx is already running"
echo "-------------------------------------------"
fi
echo
echo
if [ $(docker ps | grep -c "redis-dev") -eq 0 ]; then
echo "Starting redis-dev..."
docker-compose up -d redis-dev
else
echo "-------------------------------------------"
echo "redis is already running"
echo "-------------------------------------------"
fi
echo
echo "start blue-green deploy!"
echo
# Blue λ₯Ό κΈ°μ€μΌλ‘ νμ¬ λ μλ 컨ν
μ΄λλ₯Ό 체ν¬νλ€.
RUNNING_BLUE_CONTAINER=$(docker ps | grep blue)
DEFAULT_CONF="/home/app/nginx/default.conf"
BLUE_CONTAINER_NAME="dadok-dev-blue"
GREEN_CONTAINER_NAME="dadok-dev-green"
PORT=8080
# 컨ν
μ΄λ μ€μμΉ
# BLUE 컨ν
μ΄λκ° λμμ€μ΄μ§ μλ€λ©΄,
if [ -z "$RUNNING_BLUE_CONTAINER" ]; then
echo "blue up"
START_CONTAINER="dadok-dev-blue" # μμν 컨ν
μ΄λ
STARTED_CONTAINER="dadok-dev-green" # μλμ€μΈ ν΄ν
μ΄λ
docker-compose up -d dadok-dev-blue
sed -i "s/${GREEN_CONTAINER_NAME}/${BLUE_CONTAINER_NAME}/g" $DEFAULT_CONF
docker exec nginx-dev service nginx reload
else # BLUE 컨ν
μ΄λκ° λμμ€μ΄λΌλ©΄
echo "green up"
START_CONTAINER="dadok-dev-green" # μμν 컨ν
μ΄λ
STARTED_CONTAINER="dadok-dev-blue" # μλμ€μΈ ν΄ν
μ΄λ
docker-compose up -d dadok-dev-green
sed -i "s/${BLUE_CONTAINER_NAME}/${GREEN_CONTAINER_NAME}/g" $DEFAULT_CONF
docker exec nginx-dev service nginx reload
fi
echo "start container : $START_CONTAINER"
echo "started container : $STARTED_CONTAINER"
# μλ‘μ΄ μ»¨ν
μ΄λκ° μ λλ‘ λ΄λμ§ νμΈ
count=0
while [ $count -lt 10 ]; do
echo "$START_CONTAINER health check...."
HEALTH=$(docker exec nginx-dev curl http://$START_CONTAINER:8080)
if [ -n "$HEALTH" ]; then
break
fi
sleep 3
count=$((count+1))
done
if [ $count -ge 11 ]; then
echo "Error: Health check failed after 10 retries. deploy fail. count : $count"
count=0
exit 1
fi
echo "-------------------------------------------"
echo "nginx reload"
docker exec nginx-dev service nginx reload
echo "-------------------------------------------"
# μ΄μ 컨ν
μ΄λ μ’
λ£
if [ $(docker ps | grep -c "$STARTED_CONTAINER") -eq 1 ]; then
docker-compose stop "$STARTED_CONTAINER"
docker rm $STARTED_CONTAINER
else
echo "$STARTED_CONTAINER is not running."
fi
## end