-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.sh
executable file
·53 lines (43 loc) · 1.87 KB
/
update.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
#!/bin/bash
reload_nginx() {
echo "Reloading nginx"
docker exec nginx /usr/sbin/nginx -s reload
}
zero_downtime_deploy() {
service_name=$1
echo "------------------------------------------"
echo "Redeploying $service_name"
old_container_id=$(docker ps -f name=$service_name -q | tail -n1)
echo "Old container ID: $old_container_id ($service_name)"
# bring a new container online, running new code
# (nginx continues routing to the old container only)
docker compose up -d --no-deps --scale $service_name=2 --no-recreate $service_name
# wait for new container to be available
new_container_id=$(docker ps -f name=$service_name -q | head -n1)
new_container_ip=$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $new_container_id)
echo "New container ID: $new_container_id ($service_name)"
echo "New container IP: $new_container_ip ($service_name)"
curl --silent --include --retry-connrefused --retry 60 --retry-delay 1 --fail http://$new_container_ip:8080/healthcheck/live/ || exit 1
# start routing requests to the new container (as well as the old)
reload_nginx
# take the old container offline
echo "Stopping and removing $old_container_id ($service_name)"
docker stop $old_container_id
docker rm $old_container_id
docker compose up -d --no-deps --scale $service_name=1 --no-recreate $service_name
# stop routing requests to the old container
reload_nginx
echo "$service_name updated"
}
git pull
docker compose up -d
docker compose pull
# zero_downtime_deploy cms
# zero_downtime_deploy search_api
zero_downtime_deploy search
zero_downtime_deploy frontend
zero_downtime_deploy frontend-develop
zero_downtime_deploy frontend-enrichment
df -h -k /dev/sda1
# Prune Docker if disk usage is above 80%
if df -hP -k /dev/sda1 | awk '{if ($5+0>=80) exit 1}'; then echo "Space OK"; else docker system prune --force --all --volumes; fi