Last active
March 24, 2021 14:09
-
-
Save mateusnava/43527c844d544598be96e0b212e63d92 to your computer and use it in GitHub Desktop.
Script for docker-compose deploy with zero downtime
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| DOCKER_COMPOSE_NAME='web' | |
| DOCKER_COMPOSE_FOLDER='/home/mateus/Projetos/api-agro1' | |
| cd $DOCKER_COMPOSE_FOLDER | |
| echo '==> Pulling...' | |
| docker-compose pull | |
| echo '==> Scaling...' | |
| container_name=`docker-compose ps | grep -m 1 $DOCKER_COMPOSE_NAME | cut -d " " -f1` | |
| docker-compose up -d --no-deps --scale $DOCKER_COMPOSE_NAME=2 --no-recreate | |
| new_container_name=`docker-compose ps | grep $DOCKER_COMPOSE_NAME | tail -1 | cut -d " " -f1` | |
| echo "New container is $new_container_name" | |
| echo '==> Waiting for health...' | |
| while true; do | |
| if [[ `docker inspect --format='{{json .State.Health.Status}}' $new_container_name` = *"\"healthy\""* ]]; then | |
| break | |
| fi | |
| echo "$(date) - still trying" | |
| sleep 5 | |
| done | |
| echo '==> New container is running!!!' | |
| echo '==> Removing old container...' | |
| sleep 1 | |
| docker rm --force $container_name | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment