-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrollingupdate.sh
24 lines (20 loc) · 933 Bytes
/
rollingupdate.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
recreate_service() {
echo "Building new images for $1."
docker compose build worker
echo "Rolling update for $1."
PREVIOUS_CONTAINER=$(docker ps --format "table {{.ID}} {{.Names}} {{.CreatedAt}}" | grep $1 | awk -F " " '{print $1}')
CURRENT_COUNT=$(echo $PREVIOUS_CONTAINER | wc -w)
echo "Current count: $CURRENT_COUNT, adding $CURRENT_COUNT more."
docker compose up -d --no-deps --scale $1=$(($CURRENT_COUNT+$CURRENT_COUNT)) --no-recreate $1
echo "Sleeping 20 seconds to make sure the containers have started correctly."
sleep 20
echo "Killing and removing old containers."
docker kill -s SIGTERM $PREVIOUS_CONTAINER
sleep 1
docker rm -f $PREVIOUS_CONTAINER
echo "Reverting back to $CURRENT_COUNT amount."
docker compose up -d --no-deps --scale $1=$CURRENT_COUNT --no-recreate $1
}
#Always do a git pull before applying an update
git pull
recreate_service "worker"