๐Ÿ”„ CI/CD Pipeline with Docker

Automated Build, Test, and Deployment Pipeline - DevOps Best Practices

๐Ÿ”„ CI/CD Pipeline Flow

Automated continuous integration and deployment pipeline using Docker containers. From code commit to production deployment in minutes, not hours.

๐Ÿ”จ
Build
โœ“ Completed
๐Ÿงช
Test
โœ“ Passed
๐Ÿ”
Security Scan
โœ“ Clean
๐Ÿš€
Deploy
โณ Ready
Pipeline Logs 0 logs
[00:00:00] [INFO] Pipeline ready. Click "Run Pipeline" to start.
0s
Build Time
0
Tests Executed
0%
Code Coverage
0s
Deploy Time
๐Ÿ”จ
Build Stage

Docker Multi-Stage Build: Compile application code, install dependencies, and create optimized production images with minimal size.

  • โœ… Multi-stage Dockerfile optimization
  • โœ… Layer caching for faster builds
  • โœ… Dependency installation and compilation
  • โœ… Image tagging with version and commit SHA
๐Ÿงช
Test Stage

Automated Testing: Run unit tests, integration tests, and end-to-end tests in isolated Docker containers to ensure code quality.

  • โœ… Unit tests with code coverage reports
  • โœ… Integration tests with database containers
  • โœ… E2E tests in isolated environments
  • โœ… Parallel test execution for speed
๐Ÿ”
Security Scan

Vulnerability Detection: Scan Docker images for known vulnerabilities, security issues, and compliance violations before deployment.

  • โœ… CVE vulnerability scanning with Trivy
  • โœ… Dependency security audit
  • โœ… Container image best practices check
  • โœ… Secret detection and prevention
๐Ÿš€
Deploy Stage

Automated Deployment: Push images to registry, update Kubernetes manifests, and deploy to production with zero-downtime rolling updates.

  • โœ… Docker image push to registry (Docker Hub/ECR)
  • โœ… Kubernetes rolling update deployment
  • โœ… Health checks and readiness probes
  • โœ… Automatic rollback on failure

๐Ÿ“ Pipeline Configuration

.github/workflows/ci-cd.yml
name: Docker CI/CD Pipeline on: push: branches: [ main, develop ] pull_request: branches: [ main ] jobs: build-and-test: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v3 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - name: Build Docker image run: | docker build -t myapp:${{ github.sha }} . docker build -t myapp:latest . - name: Run unit tests run: | docker run --rm myapp:${{ github.sha }} npm test - name: Run integration tests run: | docker-compose -f docker-compose.test.yml up --abort-on-container-exit - name: Security scan with Trivy uses: aquasecurity/trivy-action@master with: image-ref: myapp:${{ github.sha }} format: 'sarif' output: 'trivy-results.sarif' - name: Login to Docker Hub if: github.ref == 'refs/heads/main' uses: docker/login-action@v2 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Push to Docker Hub if: github.ref == 'refs/heads/main' run: | docker tag myapp:${{ github.sha }} username/myapp:${{ github.sha }} docker tag myapp:latest username/myapp:latest docker push username/myapp:${{ github.sha }} docker push username/myapp:latest - name: Deploy to Kubernetes if: github.ref == 'refs/heads/main' run: | kubectl set image deployment/myapp myapp=username/myapp:${{ github.sha }} kubectl rollout status deployment/myapp
Dockerfile - Multi-Stage Build
# Build stage FROM node:18-alpine AS builder WORKDIR /app COPY package*.json ./ RUN npm ci --only=production COPY . . RUN npm run build # Production stage FROM node:18-alpine WORKDIR /app # Copy only necessary files from builder COPY --from=builder /app/dist ./dist COPY --from=builder /app/node_modules ./node_modules COPY --from=builder /app/package.json ./ # Security: Run as non-root user RUN addgroup -g 1001 -S nodejs && \ adduser -S nodejs -u 1001 USER nodejs EXPOSE 3000 HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ CMD node healthcheck.js CMD ["node", "dist/server.js"]
docker-compose.test.yml
version: '3.8' services: app: build: . environment: - NODE_ENV=test - DB_HOST=postgres depends_on: postgres: condition: service_healthy command: npm run test:integration postgres: image: postgres:15-alpine environment: - POSTGRES_DB=test_db - POSTGRES_USER=test - POSTGRES_PASSWORD=test healthcheck: test: ["CMD-SHELL", "pg_isready -U test"] interval: 5s timeout: 3s retries: 5
๐Ÿ”ง
Tools & Technologies
Docker GitHub Actions Kubernetes Trivy Docker Compose Docker Buildx Container Registry Jest
๐ŸŽฏ
Pipeline Benefits
  • โšก Automated testing on every commit
  • ๐Ÿ”’ Security scanning before deployment
  • ๐Ÿš€ Zero-downtime deployments
  • ๐Ÿ“Š Build and deployment metrics

๐Ÿ“Š Pipeline Monitoring

98.5%
Success Rate
5.2m
Avg Build Time
1,247
Total Builds
12
Deployments Today
๐Ÿ“ˆ
Performance Metrics

Key Performance Indicators:

  • โฑ๏ธ Lead Time: 8 minutes (commit to production)
  • ๐Ÿ“Š Deployment Frequency: 15-20 per day
  • ๐Ÿ”„ Change Failure Rate: 1.5%
  • โšก Mean Time to Recovery: 12 minutes
๐Ÿ”
Quality Metrics

Code Quality & Testing:

  • โœ… Test Coverage: 92% (minimum 80% required)
  • ๐Ÿงช Unit Tests: 1,200+ automated tests
  • ๐Ÿ”’ Security Vulnerabilities: 0 critical, 2 low
  • ๐Ÿ“‹ Code Linting: ESLint + Prettier compliance
๐ŸŽฏ
Best Practices
  • โœ… Automated rollback on deployment failure
  • โœ… Blue-green deployment strategy
  • โœ… Container image scanning in every build
  • โœ… Comprehensive logging and monitoring
  • โœ… Infrastructure as Code (IaC) with version control
๐Ÿ›ก๏ธ
Security Features
  • ๐Ÿ”’ Image signing and verification
  • ๐Ÿ” Secrets management with HashiCorp Vault
  • ๐Ÿ›ก๏ธ Runtime security monitoring
  • ๐Ÿ“ Compliance auditing and reporting
  • ๐Ÿ” Continuous vulnerability scanning