CYBER ENGINE v6.0
Type to search across all LinuxLab documentation & cheatsheets...
    Home / DevOps / Documentation Note

    DevOps CI/CD: Automated Multi-Stage Docker Builds & GitHub Actions

    DevOps Aug 16, 2026 1 min read

    Optimizing Modern Containerized Delivery Pipelines

    Building minimal, secure container images and deploying them via automated GitOps pipelines is at the core of DevOps engineering.

    1. Production Multi-Stage Dockerfile

    # Build Stage
    FROM node:20-alpine AS builder
    WORKDIR /app
    COPY package*.json ./
    RUN npm ci --only=production
    COPY . .
    RUN npm run build
    
    # Final Distroless Production Image
    FROM gcr.io/distroless/nodejs20-debian12
    WORKDIR /app
    COPY --from=builder /app/dist ./dist
    COPY --from=builder /app/node_modules ./node_modules
    USER nonroot:nonroot
    EXPOSE 8080
    CMD ["dist/server.js"]

    2. GitHub Actions Deployment Workflow

    name: Production CI/CD Pipeline
    
    on:
      push:
        branches: [ main ]
    
    jobs:
      build-and-deploy:
        runs-on: ubuntu-latest
        steps:
          - name: Checkout Source Code
            uses: actions/checkout@v4
    
          - name: Set up Docker Buildx
            uses: docker/setup-buildx-action@v3
    
          - name: Log in to Container Registry
            uses: docker/login-action@v3
            with:
              registry: ghcr.io
              username: ${{ github.actor }}
              password: ${{ secrets.GITHUB_TOKEN }}
    
          - name: Build and Push Docker Image
            uses: docker/build-push-action@v5
            with:
              context: .
              push: true
              tags: ghcr.io/linuxlab/api-service:latest
              cache-from: type=gha
              cache-to: type=gha,mode=max