CI/CD Basics
What CI/CD Means
CI validates code automatically through build, lint, tests, and security scans.
CD delivers changes to staging or production through a predictable pipeline.
Typical Pipeline
- Checkout the code
- Install dependencies
- Lint and format checks
- Unit tests
- Build artifact or image
- Security scanning
- Push the artifact to a registry
- Deploy to an environment
What Matters in Infrastructure Pipelines
- separate environments:
dev, stage, prod
- secrets management
- rollback strategy
- artifact immutability
- audit trail
Minimal GitHub Actions Example
name: ci
on:
push:
branches: [main]
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: npm ci
- run: npm test
Minimal Deployment Approach
- build once
- promote the same artifact between environments
- do not rebuild a separate artifact just for
prod
Practice
- Secrets should not live in the repository.
- A production deployment without tests, review, and a rollback plan is usually a bad idea.
- For infrastructure changes, requiring
plan or dry-run as a mandatory stage is a good default.