forked from woowacourse-teams/2023-dong-gle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
72 lines (59 loc) ยท 2.15 KB
/
deploy.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
#!/bin/bash
# deploy.sh๊ฐ ์คํ ์ค์ธ์ง ํ์ธ
if [ -e /tmp/deploy.lock ]; then
echo "Deployment is in progress"
exit 1
fi
# deploy.sh๊ฐ ์คํ ์ค์ด์ง ์๋ค๋ฉด lock ํ์ผ ์์ฑ
touch /tmp/deploy.lock
# Blue ๋ฅผ ๊ธฐ์ค์ผ๋ก ํ์ฌ ๋ ์๋ ์ปจํ
์ด๋๋ฅผ ์ฒดํฌํ๋ค.
EXIST_BLUE=$(sudo docker compose -p compose-blue -f compose-blue.yml ps | grep Up)
# ์ปจํ
์ด๋ ์ค์์นญ
if [ -z "$EXIST_BLUE" ]; then
echo "blue up"
sudo docker compose -p compose-blue -f compose-blue.yml pull
sudo docker compose -p compose-blue -f compose-blue.yml up -d
BEFORE_COMPOSE_COLOR="green"
AFTER_COMPOSE_COLOR="blue"
else
echo "green up"
sudo docker compose -p compose-green -f compose-green.yml pull
sudo docker compose -p compose-green -f compose-green.yml up -d
BEFORE_COMPOSE_COLOR="blue"
AFTER_COMPOSE_COLOR="green"
fi
sleep 10
INFRA_PROFILE=$1
# ๋์ปค ๋คํธ์ํฌ ์ด๋ฆ
NETWORK_NAME="donggle-network"
# ๋์ปค ๋คํธ์ํฌ๊ฐ ์กด์ฌํ๋์ง ํ์ธ
sudo docker network inspect $NETWORK_NAME >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Network '$NETWORK_NAME' already exists, nothing to do here..."
else
echo "Network '$NETWORK_NAME' does not exist, creating..."
sudo docker network create $NETWORK_NAME
if [ $? -eq 0 ]; then
echo "Network '$NETWORK_NAME' created successfully!"
else
echo "Failed to create network '$NETWORK_NAME'"
exit 1
fi
fi
export AFTER_COMPOSE_COLOR
# ์๋ก์ด ์ปจํ
์ด๋๊ฐ ์ ๋๋ก ๋ด๋์ง ํ์ธ
EXIST_AFTER=$(sudo docker compose -p compose-${AFTER_COMPOSE_COLOR} -f compose-${AFTER_COMPOSE_COLOR}.yml ps | grep Up)
if [ -n "$EXIST_AFTER" ]; then
# nginx.config๋ฅผ ์ปจํ
์ด๋์ ๋ง๊ฒ ๋ณ๊ฒฝํด์ฃผ๊ณ reload ํ๋ค
envsubst '${AFTER_COMPOSE_COLOR}' < conf-${INFRA_PROFILE}/nginx.template > conf-${INFRA_PROFILE}/nginx.conf
sudo docker compose -f compose-nginx.yml exec nginx nginx -s reload
# ์ด์ ์ปจํ
์ด๋ ์ข
๋ฃ
sudo docker compose -p compose-${BEFORE_COMPOSE_COLOR} -f compose-${BEFORE_COMPOSE_COLOR}.yml down
echo "$BEFORE_COMPOSE_COLOR down"
# lock ํ์ผ ์ญ์
rm -f /tmp/deploy.lock
else
echo "deploy fail"
rm -f /tmp/deploy.lock
exit 1
fi