-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy-dev.sh
123 lines (93 loc) · 3.51 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/bash
export $(grep -v '^#' docker/.env | sed 's/ *= */=/g' | xargs)
IS_GREEN_EXIST=$(sudo docker ps | grep green)
DIR=~/docker
SPRING_GREEN_PORT=4001
SPRING_BLUE_PORT=4002
NESTJS_GREEN_PORT=3001
NESTJS_BLUE_PORT=3002
DOCKERHUB_PASSWORD=$DOCKERHUB_PASSWORD
SPRING_GREEN_NAME="spring-green"
SPRING_BLUE_NAME="spring-blue"
NESTJS_GREEN_NAME="nestjs-green"
NESTJS_BLUE_NAME="nestjs-blue"
# green up
if [ -z $IS_GREEN_EXIST ];then
echo "### BLUE -> GREEN ####"
echo ">>> pull green image"
sudo docker login -u makerscrew -p DOCKERHUB_PASSWORD
(cd $DIR && sudo docker compose pull caddy)
(cd $DIR && sudo docker compose pull swagger)
(cd $DIR && sudo docker compose pull nestjs-green)
(cd $DIR && sudo docker compose pull spring-green)
(cd $DIR && sed -i "s/^SPRING_NAME=.*/SPRING_NAME=${SPRING_GREEN_NAME}/" .env)
(cd $DIR && sed -i "s/^NESTJS_NAME=.*/NESTJS_NAME=${NESTJS_GREEN_NAME}/" .env)
(cd $DIR && sudo docker network create caddy)
sleep 5
echo ">>> up green container"
(cd $DIR && sudo docker compose --env-file .env -f docker-compose.yml -f docker-compose.dev.yml up caddy nestjs-green spring-green swagger -d --build)
while [ 1 = 1 ]; do
echo ">>> nestjs green health check ..."
sleep 3
STATUS_CODE_NESTJS=$(curl -o /dev/null -s -w "%{http_code}" localhost:3001/)
if [ "$STATUS_CODE_NESTJS" -eq 200 ]; then
echo ">>> nestjs health check success !"
break;
fi
done;
while [ 1 = 1 ]; do
echo ">>> spring green health check ..."
sleep 3
STATUS_CODE_SPRING=$(curl -o /dev/null -s -w "%{http_code}" localhost:4001/health/v2)
if [ "$STATUS_CODE_SPRING" -eq 200 ]; then
echo ">>> spring health check success !"
break;
fi
done;
sleep 3
echo ">>> down blue container"
(cd $DIR && sudo docker compose stop spring-blue)
(cd $DIR && sudo docker compose stop nestjs-blue)
(cd $DIR && sudo docker compose rm -f spring-blue)
(cd $DIR && sudo docker compose rm -f nestjs-blue)
# blue up
else
echo "### GREEN -> BLUE ###"
echo ">>> pull blue image"
sudo docker login -u makerscrew -p DOCKERHUB_PASSWORD
(cd $DIR && sudo docker compose pull caddy)
(cd $DIR && sudo docker compose pull swagger)
(cd $DIR && sudo docker compose pull nestjs-blue)
(cd $DIR && sudo docker compose pull spring-blue)
(cd $DIR && sed -i "s/^SPRING_NAME=.*/SPRING_NAME=${SPRING_BLUE_NAME}/" .env)
(cd $DIR && sed -i "s/^NESTJS_NAME=.*/NESTJS_NAME=${NESTJS_BLUE_NAME}/" .env)
(cd $DIR && sudo docker network create caddy)
sleep 5
echo ">>> up blue container"
(cd $DIR && sudo docker compose --env-file .env -f docker-compose.yml -f docker-compose.dev.yml up caddy nestjs-blue spring-blue swagger -d --build)
while [ 1 = 1 ]; do
echo ">>> nestjs blue health check ..."
sleep 3
STATUS_CODE_NESTJS=$(curl -o /dev/null -s -w "%{http_code}" localhost:3002/)
if [ "$STATUS_CODE_NESTJS" -eq 200 ]; then
echo ">>> nestjs health check success !"
break;
fi
done;
while [ 1 = 1 ]; do
echo ">>> spring blue health check ..."
sleep 3
STATUS_CODE_SPRING=$(curl -o /dev/null -s -w "%{http_code}" localhost:4002/health/v2)
if [ "$STATUS_CODE_SPRING" -eq 200 ]; then
echo ">>> spring health check success !"
break;
fi
done;
sleep 3
echo ">>> down green container"
(cd $DIR && sudo docker compose stop spring-green)
(cd $DIR && sudo docker compose stop nestjs-green)
(cd $DIR && sudo docker compose rm -f spring-green)
(cd $DIR && sudo docker compose rm -f spring-green)
fi
sudo docker image prune -f