C P M

Automated CI/CD Deployment with Docker Swarm and GitHub Actions

cybersecurity

Modern Continuous Deployment with Container Orchestration

Direct Answer: Automated CI/CD pipelines combine GitHub Actions workflows for automated code linting, unit testing, and Docker container compilation with SSH-based deployment webhooks that instruct Docker Swarm or Kubernetes to perform zero-downtime rolling service updates.

1. Zero-Downtime Rolling Update Architecture

In a Docker Swarm cluster, services are updated incrementally. By setting order: start-first, Docker spins up healthy new containers with the updated code before terminating legacy containers. If the new container fails health checks, Swarm halts the update and rolls back automatically.

# Docker Compose Stack Deployment Configuration
version: "3.8"
services:
  web_app:
    image: registry.codepromax.com.de/production/app:latest
    deploy:
      replicas: 4
      update_config:
        parallelism: 1
        delay: 10s
        order: start-first
        failure_action: rollback
      restart_policy:
        condition: on-failure
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
      interval: 10s
      timeout: 5s
      retries: 3

2. Hardened GitHub Actions Deployment Pipeline

name: Production CI/CD Pipeline
on:
  push:
    branches: [ main ]

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Log in to Private Docker Registry
        uses: docker/login-action@v2
        with:
          registry: registry.codepromax.com.de
          username: ${{ secrets.REGISTRY_USER }}
          password: ${{ secrets.REGISTRY_PASSWORD }}

      - name: Build & Push Image
        run: |
          docker build -t registry.codepromax.com.de/production/app:${{ github.sha }} .
          docker push registry.codepromax.com.de/production/app:${{ github.sha }}

      - name: Trigger Swarm Rolling Update via SSH
        uses: appleboy/[email protected]
        with:
          host: ${{ secrets.PRODUCTION_SWARM_MANAGER }}
          username: cicd_deployer
          key: ${{ secrets.DEPLOY_PRIVATE_KEY }}
          script: |
            docker service update 
              --image registry.codepromax.com.de/production/app:${{ github.sha }} 
              cpm_production_web_app

Need Production-Grade DevOps & 24/7 SysAdmin Services?

At CodeProMax Tech, our senior infrastructure and software engineers design, implement, and maintain tailored enterprise solutions with 24/7 SLA engineering support.

Explore DevOps & 24/7 SysAdmin Services →

CodeProMax Tech Technical Author
Published By
Admin
Leave a Comment

Talk with an ERP & DevOps Specialist