update_api.sh 938 Bytes
Newer Older
1 2
#!/bin/bash

David Foucher's avatar
David Foucher committed
3
SERVICE_NAME=${1?"Usage: docker_update [trefle|trefle-old]"}
4 5 6 7 8

date >> update.log
echo $* >> update.log

echo "[INIT] Scaling $SERVICE_NAME up"
9 10 11
docker-compose up -d --scale $SERVICE_NAME=2 --no-recreate $SERVICE_NAME \
    || { echo "[FAILED] Can't scale $SERVICE_NAME" | tee -a update.log; exit 1; } \
    && LAST_DOCKERID=$(docker ps -ql)
12 13

until [[ $(docker ps -q -f "health=healthy" -f "id=$LAST_DOCKERID") ]]; do
14 15
    echo "[WAIT] New instance is healthy"
    sleep 1;
16 17 18 19 20 21 22 23 24
done
echo "[DONE] New container healthy" | tee -a update.log

echo "[INIT] Remove older container $SERVICE_NAME"
docker stop $(docker ps -n 2 --filter "name=_${SERVICE_NAME}_" -q | tail -1) && docker container prune -f
echo "[DONE] Remove older container" | tee -a update.log

echo "[INIT] Scaling $SERVICE_NAME down"
docker-compose up -d --scale $SERVICE_NAME=1 --no-recreate $SERVICE_NAME
25 26
echo "[DONE] Scaling down" | tee -a update.log \
    && exit 0