CI/CD with GitHub Actions: Build, Test, and Deploy Pipelines
Automating software delivery — build pipelines, testing, Docker image builds, deployment automation, and secrets management with GitHub Actions.
GitHub Actions makes CI/CD accessible without managing CI servers.
1. Basic Test Pipeline
name: CI/CD Pipeline
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
- run: npm ci
- run: npm run lint
- run: npm run test:ci
env:
CI: true
2. Docker Build and Push
build:
needs: test
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/metadata-action@v5
id: meta
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=sha,prefix=sha-
type=semver,pattern={{version}}
- uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
3. Matrix Testing
test-matrix:
strategy:
matrix:
node-version: [18, 20, 22]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm ci && npm test
4. Secrets Best Practices
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
Use GitHub Secrets (Settings > Secrets and variables) or external secret managers. Never hardcode credentials in workflow files.
5. Layer Caching
# npm dependency cache
- uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
# Docker build cache via GHA backend
- uses: docker/build-push-action@v5
with:
cache-from: type=gha
cache-to: type=gha,mode=max
Conclusion
Separate jobs for test/build/deploy. Use environments for production gating. Cache npm and Docker layers for speed. Ventra Rocket reduced deployment time from 30-minute manual steps to 5-minute automated pipelines with GitHub Actions.
Related Articles
Kubernetes Deployment Guide for Node.js Applications
Step-by-step guide to deploying Node.js on Kubernetes — Deployments, Services, HPA, health checks, and zero-downtime rollouts.
Docker and CI/CD Pipeline for Next.js Applications
A complete guide to containerising Next.js with Docker multi-stage builds and setting up a fully automated CI/CD pipeline with GitHub Actions for zero-downtime deployments.
Microservices Architecture with Docker and Message Queues
Design patterns for building microservices — service decomposition, async communication with RabbitMQ, circuit breakers, distributed tracing, and observability.