Skip to main content
CI/CD

Production CI/CD with GitHub Actions

Automated testing, Docker builds, and Terraform deploys in one workflow. Battle-tested patterns from 100+ production pipelines.

YE
Yassine El Horma
Lead SRE
10 pages.blog.minRead read
Feb 10, 2025
CI/CDGitHub Actions

Pipeline Architecture

A production CI/CD pipeline has four stages: lint/test, build, pre-deploy validation, and deploy. Use GitHub Actions' needs keyword to create a directed acyclic graph (DAG) of jobs.

Run lint and unit tests in parallel across multiple runners. Use matrix strategies for multi-language or multi-platform builds. Cache dependencies aggressively with actions/cache.

GitHub Actions CI/CD pipeline architectureGitHub Actions CI/CD pipeline architecture
CI/CD Pipeline — Lint, Build, Scan, Deploy
CI/CD Pipeline Stages
1
Lint & Test
Parallel runners
2
Build
Docker + Cache
3
Validate
Security scan
4
Deploy
Terraform apply

Docker Build Optimization

Use Docker BuildKit with layer caching via docker/build-push-action@v5. Enable the GitHub Actions cache backend with cache-from: type=gha and cache-to: type=gha,mode=max for 10x faster builds.

Build multi-arch images (amd64 + arm64) in parallel using QEMU or native runners. Push to ECR with immutable tags — use the Git SHA, not latest.

Docker Build Optimization
Metric
Before
After
Build Time
12 min
1.2 min 10x
Cache Hit Rate
0%
94% +94%
Image Layers
24
8 -67%

Terraform Integration

Run terraform plan on pull requests and post the plan as a PR comment using hashicorp/setup-terraform and a custom script. Require manual approval for terraform apply using environments and protection rules.

Store Terraform state in S3 with DynamoDB locking. Use OIDC for AWS authentication — never store long-lived credentials in GitHub Secrets.

.github/workflows/deploy.ymlYAML
deploy:
  needs: [test, build]
  runs-on: ubuntu-latest
  environment: production     # Requires approval
  permissions:
    id-token: write           # OIDC for AWS
  steps:
    - uses: aws-actions/configure-aws-credentials@v4
      with:
        role-to-assume: arn:aws:iam::role/deploy
    - uses: hashicorp/setup-terraform@v3
    - run: terraform apply -auto-approve
pages.blog.shareArticle:

pages.blog.ctaTitle

pages.blog.ctaDesc

pages.blog.ctaBtn
SOC2 15-Min SLA 99.99% Uptime