CI/CD Concepts
Here are my notes on CI/CD.
Table of Contents
- Core CI Stages
- Source checkout & environment setup
- Static analysis & linting
- Formakbding & code quality gates
- Building & packaging
- Testing
- Code coverage & test reporting
- Artifact & environment management
- Artifact storage
- Configuration & secrets
- CD / Deployment Stages
- Staging / test environment deployment
- Deployment strategies
- Production deployment
- Post-deploy & operations
- Verification & monitoring
- Rollback & recovery
- Supporting pipeline features
- Caching & optimization
- Branch / environment policies
- Notifications & reporting
- Example high-level flow (simplified)
Core CI Stages
Source checkout & environment setup
- Fetch code from VCS (e.g. git clone, checkout specific commit or PR)
- Restore or install dependencies (e.g. language packages, system packages)
- Set up build tools (compilers, SDKs, build caches)
Static analysis & linting
- Style linters (e.g. eslint, flake8, gofmt, prekbdier)
- Static analysis (e.g. pylint, sonarqube, tsc, clang-tidy)
- Security linters / SAST (e.g. bandit, semgrep, brakeman)
- Dependency vulnerability scan / SCA (e.g. npm audit, pip-audit, trivy, snyk)
- License / SBOM generation and checks
- Auto-formakbding (e.g. black, gofmt, rustfmt)
- Enforce code coverage thresholds
- Enforce quality gates (e.g. no new critical issues, complexity limits)
Building & packaging
- Compile / build:
-
- Frontend bundles (e.g. webpack, vite, rollup)
- Backend binaries or artifacts (e.g. maven, gradle, msbuild, cargo)
- Package:
-
- Containers (e.g. Docker images)
- Language-specific artifacts (e.g. .jar, .whl, .gem, .tgz)
- OS packages (e.g. .deb, .rpm)
- Versioning & tagging (e.g. semantic versioning, git tags)
Testing
- Unit tests. Fast, in-memory; run on every commit
- Integration tests: Talk to real or test instances of DBs, queues, services
- Component / contract tests: API contract verification between services
- End-to-end (E2E) tests: Browser/UI tests, API flows, user journeys
- Regression and smoke tests: Focused tests ensuring key paths still work
- Performance & load tests (often in later stages or separate pipelines)
- Security tests (DAST, API fuzzing); may be separate jobs
Code coverage & test reporting
- Collect coverage (e.g. lcov, coverage.py, jacoco)
- Publish coverage and test reports (HTML, JUnit XML, etc.)
- Enforce minimum coverage or “no drop in coverage” rules
Artifact & environment management
Artifact storage
- Store build outputs in an artifact repository:
-
- Docker/image registry
- Binary repository (e.g. Artifactory, Nexus, GitHub Packages)
- CI artifact storage (for logs, reports, temporary builds)
Configuration & secrets
- Manage environment-specific configuration (dev/stage/prod)
- Inject secrets securely: Secret managers (e.g. Vault, KMS, SSM, GitHub Actions secrets)
- Template or generate configs (e.g. helm, kustomize, dotenv)
CD / Deployment Stages
Staging / test environment deployment
- Deploy built artifact to:
-
- Test/staging Kubernetes namespace
- Test VMs or PaaS (e.g. Heroku, Cloud Run)
- Run smoke/E2E tests against staging
- Data / schema migrations in non-prod
Deployment strategies
Common strategies in CI/CD:
- Blue–green deployments: Keep old (blue) and new (green) environment; cut traffic over when ready
- Canary releases: Release to a small % of users, then gradually increase
- Rolling updates: Replace instances gradually with new version
- Recreate: Take down old version, then start new (simple but risky)
- Feature flags:Deploy dark, enable functionality via flags at runtime
Production deployment
- Promotion of the *same* artifact from staging to production
- Automated or manual approval gates:
- Human approval step
- Policy-as-code checks
- Database migrations / rollbacks
- Infrastructure changes
- IaC tools (e.g. terraform, pulumi, ansible, cloudformation)
Post-deploy & operations
Verification & monitoring
- Automated health checks (readiness/liveness, /health endpoints)
- Log checks for errors after deploy
- Metrics / observability:
- Error rates, latency, throughput
- SLO / SLA checks
- Synthetic monitoring (scripted user journeys)
Rollback & recovery
- Automated rollback if health checks or metrics fail
- Versioned releases or deployment history
- Database rollback or forward-fix strategies
Supporting pipeline features
Caching & optimization
- Cache:
- Dependencies (e.g. node_modules, .m2, pip cache)
- Build intermediates
- Parallelization of independent jobs (lint, unit tests, build, etc.)
- Matrix builds:
- Multiple OS, language versions, or dependency sets
Branch / environment policies
- Different pipelines per branch:
- PR branches: lint, tests, build only
- Main/develop: full pipeline + deploy to dev/stage
- Release branches/tags: deploy to production
- Protected branches and required checks
- Triggers:
- On push, PR, schedule (cron), or manual
Notifications & reporting
- Status notifications: Chat (Slack, Matrix, etc.), email, dashboards
- Build and deploy history
- Links to test/coverage reports, logs, artifacts
Example high-level flow (simplified)
- Checkout code and restore dependencies
- Run linters and static analysis
- Build artifacts (binary / container)
- Run unit and integration tests
- Publish artifacts to registry
- Deploy to staging environment
- Run smoke/E2E tests on staging
- With approval, deploy to production (blue–green/canary/rolling)
- Monitor and rollback automatically if needed
Copyright ©2023-2026 Søren Lund
Last modified on Wednesday, Apr 1, 2026
