feat(deploy): implement blue-green deployment strategy

This commit replaces the previous deployment mechanism with a blue-green strategy to lay the groundwork for zero-downtime deployments.
Key changes:
Introduces a deploy-blue-green.sh script to manage "blue" and "green" container sets, creating versioned releases.
Updates the Anubis gatekeeper template to dynamically route traffic based on the active deployment color, allowing for seamless traffic switching.
Modifies Docker Compose files to include color-specific labels and environment variables.
Adapts the GitHub Actions workflow to execute the new blue-green deployment process.
Removes the old, now-obsolete deployment and health check scripts.
Note: Automated rollback on health check failure is not yet implemented. Downgrades can be performed manually by switching the active color.
This commit is contained in:
badblocks 2025-06-12 16:56:36 -07:00
parent a58a0e642a
commit 30ce126a07
No known key found for this signature in database
19 changed files with 1166 additions and 591 deletions

View file

@ -1,4 +1,7 @@
x-common: &common
image: badbl0cks/pkmntrade-club:${IMAGE_TAG:-stable}
#image: ghcr.io/xe/x/httpdebug
#entrypoint: ["/ko-app/httpdebug", "--bind", ":8000"]
restart: always
env_file:
- .env
@ -6,31 +9,42 @@ x-common: &common
services:
web:
<<: *common
image: ghcr.io/xe/x/httpdebug
entrypoint: ["/ko-app/httpdebug", "--bind", ":8000"]
#image: badbl0cks/pkmntrade-club:stable
environment:
- DEBUG=False
- DISABLE_SIGNUPS=True
- PUBLIC_HOST=${DOMAIN_NAME}
- ALLOWED_HOSTS=${DOMAIN_NAME},127.0.0.1
- DEPLOYMENT_COLOR=${DEPLOYMENT_COLOR:-blue}
labels:
- "enable_gatekeeper=true"
- "deployment.color=${DEPLOYMENT_COLOR:-blue}"
- "deployment.image_tag=${IMAGE_TAG:-stable}"
deploy:
mode: replicated
replicas: ${REPLICA_COUNT}
healthcheck:
test: ["CMD", "curl", "-f", "http://127.0.0.1:8000/health/"]
interval: 5s
timeout: 3s
retries: 2
start_period: 60s
stop_grace_period: 200s # 20s buffer + 180s workers-kill-timeout
celery:
<<: *common
environment:
- DEBUG=False
- DISABLE_SIGNUPS=True
- PUBLIC_HOST=pkmntrade.club
- ALLOWED_HOSTS=pkmntrade.club,127.0.0.1
- DEPLOYMENT_COLOR=${DEPLOYMENT_COLOR:-blue}
labels:
- "enable_gatekeeper=true"
deploy:
mode: replicated
replicas: 4
# healthcheck:
# test: ["CMD", "curl", "-f", "http://127.0.0.1:8000/health"]
# interval: 30s
# timeout: 10s
# retries: 3
# start_period: 30s
# celery:
# <<: *common
# image: badbl0cks/pkmntrade-club:stable
# environment:
# - DEBUG=False
# - DISABLE_SIGNUPS=True
# - PUBLIC_HOST=pkmntrade.club
# - ALLOWED_HOSTS=pkmntrade.club,127.0.0.1
# command: ["celery", "-A", "pkmntrade_club.django_project", "worker", "-l", "INFO", "-B", "-E"]
- "deployment.color=${DEPLOYMENT_COLOR:-blue}"
- "deployment.image_tag=${IMAGE_TAG:-stable}"
command: ["celery", "-A", "pkmntrade_club.django_project", "worker", "-l", "INFO", "-B", "-E"]
stop_grace_period: 200s # match our longest stop_grace_period (currently web service is 200s)
networks:
default:
name: pkmntrade-club_network
external: true