How euron-tech/bluegreen_test works
Purpose and entry points
This is a teaching-scale FastAPI service demonstrating zero-downtime AWS ECS/Fargate blue-green deployment with automatic rollback. Runtime entry point is app/main.py; containerization starts at Dockerfile; local multi-service execution is docker-compose.yml. Deployment orchestration is available through deploy.ps1 and GitHub Actions at .github/workflows/deploy.yml.
Application and HTTP contract
The FastAPI app serves the color-coded page, health endpoint, and metrics endpoint used by ALB, smoke tests, and monitoring. app/observability.py adds structured logging, request IDs, and metrics instrumentation around application requests. Presentation assets are isolated in app/templates/index.html and app/static/style.css.
Container and local environments
The image packages the Python 3.12/FastAPI application for Linux AMD64 Fargate execution (Dockerfile, requirements.txt). docker-compose.yml supports local blue on port 8000, optional green on 9000, and opt-in observability/load profiles. This mirrors the production separation between public production traffic and deployment validation traffic.
AWS traffic and compute plane
Terraform provisions the network, public ALB, port 80 production listener, port 9000 test listener, two swappable target groups, ECR, ECS cluster/service, Fargate task definition, IAM roles, and GitHub OIDC trust. The central infrastructure definition is terraform/main.tf, with environment and trust inputs in terraform/variables.tf and externally consumed endpoints/role ARNs in terraform/outputs.tf.
Blue-green deployment control plane
CodeDeploy coordinates ECS blue-green releases: a candidate task set is validated through the green listener before traffic is shifted on the production listener; failed health checks retain or restore the live version. appspec.yaml declares the CodeDeploy deployment binding. .github/workflows/deploy.yml runs branch-specific flow: dev validates/builds only, while test deploys and checks port 9000, and main promotes through production blue-green deployment.
Delivery and verification flow
The bootstrap path resolves the ECR/image-before-ECS dependency: create ECR, build/push image, then provision remaining infrastructure. deploy.ps1 automates preflight, tests, image publishing, Terraform, GitHub role setup, deployment watching, and smoke validation. Post-deployment availability is checked by scripts/smoke-test.sh; /health is the critical boundary between application correctness and ALB/CodeDeploy promotion.
Observability and operations
Production observability uses CloudWatch Logs, metrics/alarm resources, SNS notification, log metric filters, and a CloudWatch dashboard defined in terraform/monitoring.tf. The local observability stack uses Prometheus, Grafana, Loki, Promtail, and Alertmanager, configured under monitoring/prometheus.yml, monitoring/loki-config.yml, and monitoring/grafana/. GitHub authenticates to AWS through short-lived OIDC credentials rather than stored AWS keys.
Main entry points: main.tf Terraform platform · main.py FastAPI service · Dockerfile Fargate image · deploy.ps1 Deployment bootstrap
Components 17
Application
- FastAPI service · Serves page, health, and metrics endpoints.
app/main.py - Request instrumentation · Adds structured logs, request IDs, and metrics.
app/observability.py - Page assets
app/templates/index.html
Container & Local
- Fargate image · Linux AMD64 FastAPI image.
Dockerfile - Local blue/green stack · Runs blue, optional green, and opt-in monitoring profiles.
docker-compose.yml
AWS Platform
- ECR repository
terraform/main.tf - Public ALB · Port 80 carries production traffic; port 9000 validates candidates.
terraform/main.tf - Blue / green target groups
terraform/main.tf - ECS Fargate service · Runs the active and candidate task sets.
terraform/main.tf - Terraform platform · Provisions network, ALB, ECR, ECS, IAM, and deployment resources.
terraform/main.tf
Delivery Control
- CodeDeploy · Validates green before shifting production traffic and rolls back failures.
appspec.yaml - GitHub deployment workflow · Dev builds only; test validates port 9000; main promotes production.
.github/workflows/deploy.yml - GitHub OIDC trust
terraform/variables.tf - Deployment bootstrap · Builds and publishes images, applies Terraform, watches deployment, and validates.
deploy.ps1 - Smoke validation · Uses /health as the promotion boundary.
scripts/smoke-test.sh
Observability
- CloudWatch monitoring · Publishes alarms, dashboards, log filters, and SNS notifications.
terraform/monitoring.tf - Local monitoring stack · Provides local metrics, logs, dashboards, and alerting.
monitoring/prometheus.yml
Connections 23
- Request instrumentation → FastAPI service: wraps requests
- Page assets → FastAPI service: rendered by
- Fargate image → FastAPI service: packages
- Local blue/green stack → Fargate image: runs blue and green
- Local blue/green stack → Local monitoring stack: enables profiles
- Terraform platform → ECR repository: provisions
- Terraform platform → Public ALB: provisions
- Terraform platform → Blue / green target groups: provisions
- Terraform platform → ECS Fargate service: provisions
- Fargate image → ECR repository: pushed to
- ECR repository → ECS Fargate service: image source
- Public ALB → Blue / green target groups: routes production and test listeners
- Blue / green target groups → ECS Fargate service: route to task sets
- GitHub deployment workflow → GitHub OIDC trust: authenticates through
- GitHub OIDC trust → Terraform platform: assumes AWS role
- GitHub deployment workflow → CodeDeploy: starts promotion
- CodeDeploy → Blue / green target groups: validates and shifts traffic
- Deployment bootstrap → Fargate image: builds and publishes
- Deployment bootstrap → Terraform platform: applies
- Deployment bootstrap → Smoke validation: runs
- Smoke validation → Public ALB: checks /health
- FastAPI service → CloudWatch monitoring: emits production telemetry
- FastAPI service → Local monitoring stack: exposes local metrics and logs