Zero-Downtime Deployment with Docker and GitHub Actions

9 دقیقه لوستل
Docker containers and GitHub Actions CI/CD pipeline diagram
Docker containers and GitHub Actions CI/CD pipeline diagram

Why Zero-Downtime Deployment Matters

Traditional deployment methods require taking your application offline during updates, causing revenue loss and poor user experience. Zero-downtime deployment solves this with blue-green or rolling update strategies.

Architecture Overview

Our setup uses two identical environments (blue and green). Traffic is routed to one while the other is updated. After health checks pass, traffic switches instantaneously.

GitHub Actions Workflow

name: Deploy\non:\n  push:\n    branches: [main]\njobs:\n  deploy:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v4\n      - name: Build Docker image\n        run: docker build -t myapp:${{ github.sha }} .\n      - name: Push to registry\n        run: docker push myapp:${{ github.sha }}\n      - name: Deploy with rolling update\n        run: kubectl set image deployment/myapp app=myapp:${{ github.sha }}

Health Checks

Always configure readiness probes in Kubernetes. Your application should return HTTP 200 on /health only when it is fully ready to serve traffic, including database connectivity verification.

مراحل انجام کار

  1. 1
    Create Dockerfile
    Create a multi-stage Dockerfile that builds your Laravel application and produces a lean production image.
  2. 2
    Configure GitHub Actions
    Add a .github/workflows/deploy.yml file that triggers on push to main, builds the Docker image, and deploys it.
  3. 3
    Set Up Blue-Green Environments
    Provision two identical server environments and configure your load balancer to switch between them.
  4. 4
    Configure Health Checks
    Implement a /health endpoint in your Laravel application that verifies database, cache, and queue connectivity.
  5. 5
    Test the Rollback Procedure
    Always test that you can roll back to the previous version in under 60 seconds before enabling the pipeline.
شریکول: X / Twitter LinkedIn Telegram