feat: zero downtime deployment script unlocked
This commit is contained in:
+32
-4
@@ -1,8 +1,36 @@
|
||||
#!/usr/bin/env zsh
|
||||
|
||||
echo updating docker compose with latest build image
|
||||
set -e
|
||||
echo "pulling latest build image..."
|
||||
docker compose pull
|
||||
docker compose up -d
|
||||
echo finished updating and builing. Site will be down for a few seconds
|
||||
|
||||
# Check which service is running
|
||||
if docker compose ps blog-blue --filter "status=running" -q | grep -q .; then
|
||||
CURRENT="blog-blue"
|
||||
TARGET="blog-green"
|
||||
else
|
||||
CURRENT="blog-green"
|
||||
TARGET="blog-blue"
|
||||
fi
|
||||
|
||||
echo "Current: $CURRENT -> deploying Target: $TARGET"
|
||||
|
||||
# TODO dont run if 0 instances running
|
||||
# Scale current deployment to two instances, keeping the old one and adding a running env of the new one
|
||||
docker compose up -d --no-deps $TARGET
|
||||
|
||||
echo "waiting for $TARGET to pass healthcheck..."
|
||||
# docker ps --filter 'label=com.docker.compose.service=blog' --filter 'health=starting'
|
||||
until [[ "$(docker inspect --format '{{.State.Health.Status}}' $(docker compose ps -q $TARGET) 2>/dev/null)" == "healthy" ]]; do
|
||||
sleep 1
|
||||
done
|
||||
|
||||
# Give traefik backend a few seconds to update
|
||||
sleep 3
|
||||
|
||||
echo "Stopping $CURRENT..."
|
||||
docker compose stop $CURRENT
|
||||
docker compose rm -f $CURRENT
|
||||
|
||||
echo "Zero downtime deployment to $TARGET complete."
|
||||
# TODO zero downtime deployment
|
||||
# TODO run on a cron job
|
||||
|
||||
Reference in New Issue
Block a user