37 lines
1.0 KiB
Bash
Executable File
37 lines
1.0 KiB
Bash
Executable File
#!/usr/bin/env zsh
|
|
set -e
|
|
echo "pulling latest build image..."
|
|
docker compose pull
|
|
|
|
# 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
|