Last active
April 15, 2024 23:29
-
-
Save eduardofcgo/1ac7fb873150ea617f091c1f769afaf9 to your computer and use it in GitHub Desktop.
Rolling updates, zero downtime with just nginx and docker compose
This file contains 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 | |
set -e | |
docker-compose build | |
echo Update only secondary on 3333 | |
docker-compose up -d cooked_secondary | |
echo Wait until secondary is live | |
curl --silent --include --retry-connrefused --retry 30 --retry-delay 1 --fail http://localhost:3333/health.txt | |
echo Start serving secondary instead of main | |
sed -i 's/localhost:3000/localhost:3333/g' /etc/nginx/sites-enabled/default | |
service nginx reload | |
echo Waiting a bit before updating main | |
sleep 60 | |
echo Update main on 3000 | |
docker-compose up -d cooked | |
echo Wait until main is live | |
curl --silent --include --retry-connrefused --retry 30 --retry-delay 1 --fail http://localhost:3000/health.txt | |
echo Start serving main again | |
sed -i 's/localhost:3333/localhost:3000/g' /etc/nginx/sites-enabled/default | |
service nginx reload | |
echo Update all the other services | |
docker-compose up -d | |
echo Waiting a bit before stopping secondary | |
sleep 60 | |
echo Stop secondary | |
docker-compose stop cooked_secondary | |
echo Rollout completed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment