pkmntrade.club/server/gatekeepers.template.yml
badbl0cks 30ce126a07
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.
2025-06-12 16:58:55 -07:00

70 lines
2.6 KiB
YAML

services:
{{ $all_containers := whereLabelValueMatches . "enable_gatekeeper" "true" }}
# 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 := $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 }}
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 }}
env_file:
- .env
environment:
- TARGET=http://{{ $container.Name }}{{ $port }}
labels:
- gatekeeper=true
networks:
default:
aliases:
- pkmntrade-club-gatekeeper-{{ $serviceLabel }}
- gatekeeper-{{ $serviceLabel }}
{{ end }}
{{ end }}
networks:
default:
name: pkmntrade-club_network
external: true