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