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,23 +1,52 @@
services:
{{ $all_containers := whereLabelValueMatches . "enable_gatekeeper" "true" }}
{{ $all_containers = sortObjectsByKeysAsc $all_containers "Name" }}
# During deployment, both blue and green containers might exist
# So we generate gatekeepers for ALL containers with deployment.color label
{{ $color_containers := whereLabelExists $all_containers "deployment.color" }}
{{ $color_containers = sortObjectsByKeysAsc $color_containers "Name" }}
{{ range $container := $all_containers }}
{{ range $container := $color_containers }}
{{ $serviceLabel := index $container.Labels "com.docker.compose.service" }}
{{ $containerNumber := index $container.Labels "com.docker.compose.container-number" }}
{{ $deploymentColor := index $container.Labels "deployment.color" }}
{{ $port := "" }}
{{ if eq $serviceLabel "web" }}
{{ $port = ":8000" }}
{{ end }}
{{ if eq $serviceLabel "web-staging" }}
{{ $port = ":8000" }}
gatekeeper-{{ $serviceLabel }}-{{ $deploymentColor }}-{{ $containerNumber }}:
image: ghcr.io/techarohq/anubis:latest
container_name: pkmntrade-club-gatekeeper-{{ $serviceLabel }}-{{ $deploymentColor }}-{{ $containerNumber }}
env_file:
- .env
environment:
- TARGET=http://{{ $container.Name }}{{ $port }}
- DEPLOYMENT_COLOR={{ $deploymentColor }}
- TARGET_HOST=${DOMAIN_NAME}
labels:
- gatekeeper=true
- deployment.color={{ $deploymentColor }}
networks:
default:
aliases:
- pkmntrade-club-gatekeeper-{{ $serviceLabel }}
- gatekeeper-{{ $serviceLabel }}
{{ end }}
# Always include non-color-specific services
{{ $static_containers := whereLabelValueMatches . "enable_gatekeeper" "true" }}
{{ $static_containers = whereLabelDoesNotExist $static_containers "deployment.color" }}
{{ range $container := $static_containers }}
{{ $serviceLabel := index $container.Labels "com.docker.compose.service" }}
{{ $containerNumber := index $container.Labels "com.docker.compose.container-number" }}
{{ $port := "" }}
{{ if eq $serviceLabel "feedback" }}
{{ $port = ":3000" }}
{{ end }}
{{ if eq $serviceLabel "health" }}
{{ $port = ":8080" }}
{{ end }}
{{ if or (eq $serviceLabel "feedback") (eq $serviceLabel "health") }}
gatekeeper-{{ $serviceLabel }}-{{ $containerNumber }}:
image: ghcr.io/techarohq/anubis:latest
container_name: pkmntrade-club-gatekeeper-{{ $serviceLabel }}-{{ $containerNumber }}
@ -25,12 +54,6 @@ services:
- .env
environment:
- TARGET=http://{{ $container.Name }}{{ $port }}
{{ if eq $serviceLabel "web" }}
- TARGET_HOST=pkmntrade.club # pass this host to django, which checks it with ALLOWED_HOSTS
{{ end }}
{{ if eq $serviceLabel "web-staging" }}
- TARGET_HOST=staging.pkmntrade.club # pass this host to django, which checks it with ALLOWED_HOSTS
{{ end }}
labels:
- gatekeeper=true
networks:
@ -39,7 +62,9 @@ services:
- pkmntrade-club-gatekeeper-{{ $serviceLabel }}
- gatekeeper-{{ $serviceLabel }}
{{ end }}
{{ end }}
networks:
default:
name: pkmntrade-club_default
name: pkmntrade-club_network
external: true