A fully automated blue-green deployment implementation for Docker applications with zero downtime. This repository contains all scripts and configurations needed to implement a robust deployment strategy for production environments.
- Zero Downtime Deployments: Seamlessly deploy new versions without service interruption
- Blue-Green Strategy: Maintains two identical environments for reliable and quick failover
- Automatic Rollback Safety: Prevents shutting down active environments accidentally
- Health Checks: Verifies deployment success before routing traffic
- GitHub Actions Integration: Pre-configured CI/CD workflow for automated deployments
- Multi-Region Support: Orchestrated deployments across multiple regions (US, EU)
This implementation uses Docker Compose with a blue-green deployment pattern:
- Traffic Routing: An Nginx proxy routes traffic to either the blue or green environment
- Deployment Process:
- The inactive environment is updated with the new version
- Health checks verify the new version is working correctly
- Traffic is switched to the new environment
- The old environment is kept running for 30 minutes, then stopped
- Docker and Docker Compose installed
- Git repository with your application code
- For CI/CD: GitHub repository with appropriate secrets configured
/
├── docker-compose.blue-green.yml # Docker Compose configuration for blue-green environments
├── scripts/
│ ├── bg_status.sh # Script to check the status of blue-green environments
│ ├── deploy_blue_green.sh # Main deployment script to implement the blue-green pattern
│ └── pause_prod_env.sh # Utility to pause an existing production environment
└── workflows/
└── cd.yml # GitHub Actions workflow for continuous deployment
Clone this repository and place your application code in a directory named dot:
~/dot/
├── app/ # Your backend application
├── ui/ # Your frontend application
└── docker-compose.blue-green.yml # Copy from this repoThe scripts will automatically create the necessary Nginx configuration files in:
~/dot/proxy/
├── nginx.conf # Main Nginx configuration
├── conf.d/ # Additional configuration files
└── routes.conf # Environment routing configurationCopy the scripts to your application directory:
cp -r scripts ~/dot/If using GitHub Actions:
- Copy the
workflows/cd.ymlfile to your repository's.github/workflows/directory - Configure the following secrets in your GitHub repository settings:
SSH_KEY: SSH private key for deployment servers
To deploy manually on your server:
cd ~/dot
./scripts/deploy_blue_green.shThe included workflow file will automatically deploy when:
- The configured workflow (e.g., "Frontend Tests") completes successfully on the master branch
- You manually trigger the workflow through GitHub UI
Check the status of your blue-green deployment:
./scripts/bg_status.shThis will show:
- Which environment is active (blue or green)
- Status of all containers
- Results of routing tests
-
Nginx not reloading:
- Check nginx-proxy container logs:
docker logs dot-nginx-proxy-1 - Verify your Nginx configuration is valid
- Check nginx-proxy container logs:
-
Health checks failing:
- Ensure your application exposes a
/api/healthcheckendpoint - Check container logs for the app service:
docker logs dot-app-blue-1
- Ensure your application exposes a
MIT
Contributions are welcome! Please feel free to submit a Pull Request.