Skip to content

Snowboard-Software/docker_zero_downtime_deployment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Docker Zero Downtime Deployment

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.

Features

  • 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)

How It Works

This implementation uses Docker Compose with a blue-green deployment pattern:

  1. Traffic Routing: An Nginx proxy routes traffic to either the blue or green environment
  2. 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

Prerequisites

  • Docker and Docker Compose installed
  • Git repository with your application code
  • For CI/CD: GitHub repository with appropriate secrets configured

Project Structure

/
├── 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

Setup Instructions

1. Configure Your Application

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 repo

2. Configure Nginx Proxy

The 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 configuration

3. Install the Scripts

Copy the scripts to your application directory:

cp -r scripts ~/dot/

4. Set Up CI/CD (Optional)

If using GitHub Actions:

  1. Copy the workflows/cd.yml file to your repository's .github/workflows/ directory
  2. Configure the following secrets in your GitHub repository settings:
    • SSH_KEY: SSH private key for deployment servers

Deployment Methods

Manual Deployment

To deploy manually on your server:

cd ~/dot
./scripts/deploy_blue_green.sh

Automated Deployment via GitHub Actions

The 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

Monitoring and Management

Check the status of your blue-green deployment:

./scripts/bg_status.sh

This will show:

  • Which environment is active (blue or green)
  • Status of all containers
  • Results of routing tests

Troubleshooting

Common Issues

  1. Nginx not reloading:

    • Check nginx-proxy container logs: docker logs dot-nginx-proxy-1
    • Verify your Nginx configuration is valid
  2. Health checks failing:

    • Ensure your application exposes a /api/healthcheck endpoint
    • Check container logs for the app service: docker logs dot-app-blue-1

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages