DevOps Best Practices - Part 2
DevOps13 min read

CI/CD Pipeline Design for Modern Applications

Building robust CI/CD pipelines with proper testing stages, security scanning, and deployment strategies.

CI/CDGitHub ActionsTestingAutomation

Pipeline Philosophy

A good CI/CD pipeline is fast, reliable, and catches problems early. Every commit should trigger the pipeline, and developers should trust the results.

Pipeline Stages

I structure pipelines with these stages, each acting as a quality gate:

  • *Lint - Fast syntax and style checks
  • *Build - Compile code, build containers
  • *Unit Test - Fast, isolated tests
  • *Integration Test - Tests with dependencies
  • *Security Scan - Vulnerability scanning
  • *Deploy to Staging - Automated
  • *Deploy to Production - Manual approval
yaml
name: CI/CD Pipeline
on:
  push:
    branches: [main]
  pull_request:

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm run lint

  test:
    needs: lint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm test

  build:
    needs: test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Build Docker image
        run: docker build -t myapp:${{ github.sha }} .
      - name: Push to registry
        run: docker push myapp:${{ github.sha }}

  deploy-staging:
    needs: build
    if: github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    environment: staging
    steps:
      - name: Deploy to staging
        run: kubectl set image deployment/myapp myapp=myapp:${{ github.sha }}

  deploy-production:
    needs: deploy-staging
    if: github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    environment: production
    steps:
      - name: Deploy to production
        run: kubectl set image deployment/myapp myapp=myapp:${{ github.sha }}

Deployment Strategies

For production deployments, I use rolling updates with health checks. For risky changes, blue-green or canary deployments provide safer rollout:

  • *Rolling Update - Default, gradual replacement
  • *Blue-Green - Full environment switch, instant rollback
  • *Canary - Route small percentage of traffic to new version

Found this helpful?

I write about infrastructure, backend development, and DevOps. Follow along as I continue building.