-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·59 lines (45 loc) · 1.88 KB
/
Copy pathdeploy.sh
File metadata and controls
executable file
·59 lines (45 loc) · 1.88 KB
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
# Check if the local NGINX container is running
if docker ps | grep local_nginx; then
echo "Local NGINX is running. Proceeding with update."
else
echo "Local NGINX is not running. Setting up for the first time."
# Start local NGINX service
docker compose up -d --build local_nginx
# Wait until nginx is running
until docker inspect --format='{{.State.Status}}' k9-random-data-api-local_nginx-1 | grep "running"; do
echo "Waiting for nginx to be ready..."
sleep 5
done
fi
# Check which service is currently running
if docker ps | grep k9_random_data_api_blue; then
# Update green and start it
docker compose up --build -d k9_random_data_api_green
# Health check for green
until docker exec k9-random-data-api-local_nginx-1 curl -s http://k9_random_data_api_green:5000/health | grep "OK"; do
echo "Waiting for green to be ready..."
sleep 5
done
# Update local NGINX to use green
sed -i 's/server k9_random_data_api_blue:5000;/server k9_random_data_api_blue:5000 down;/' local_nginx.conf
# Reload local NGINX
docker compose exec local_nginx nginx -s reload
# Stop blue
docker compose stop k9_random_data_api_blue
else
# Update blue and start it
docker compose up --build -d k9_random_data_api_blue
# Health check for blue
until docker exec k9-random-data-api-local_nginx-1 curl -s http://k9_random_data_api_blue:5000/health | grep "OK"; do
echo "Waiting for blue to be ready..."
sleep 5
done
# Update local NGINX to use blue
sed -i 's/server k9_random_data_api_green:5000;/server k9_random_data_api_green:5000 down;/' local_nginx.conf
# Reload local NGINX
docker compose exec local_nginx nginx -s reload
# Stop green
docker compose stop k9_random_data_api_green
fi
# Optionally: Clean up unused images and containers
docker system prune -f