Nine spreads on getting code from a laptop to production safely and often: pipelines, testing, releases, infrastructure as code, configuration, GitOps and monitoring.
"Every merge triggers a pipeline that tests, builds an immutable artifact, and promotes it through environments with automated checks and a rollback."
Use the tabs or the ← → keys.
# a quick personal measure: lead time of the last 10 commits on main $ git log main -10 --format='%h %ad %s' --date=short $ gh run list --limit 10 # recent pipeline runs: how often green? how long?
"We track deploy frequency, lead time, change failure rate and time to restore, and we aim to shrink batch size."
# .github/workflows/ci.yml
name: ci
on:
push: { branches: [main] }
pull_request:
permissions: { contents: read }
concurrency: { group: ci-${{ github.ref }}, cancel-in-progress: true }
jobs:
test:
runs-on: ubuntu-latest
strategy: { matrix: { node: [20, 22] } }
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: "${{ matrix.node }}", cache: npm }
- run: npm ci
- run: npm run lint
- run: npm test -- --coverage
- run: npm run build
- uses: actions/upload-artifact@v4
with: { name: dist, path: dist }
scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm audit --audit-level=high
- uses: gitleaks/gitleaks-action@v2
"Cached, parallel, least-privilege pipelines that fail fast and produce one immutable artifact."
# integration tests against a real database in CI
services:
postgres:
image: postgres:16
env: { POSTGRES_PASSWORD: test }
ports: ["5432:5432"]
options: >-
--health-cmd "pg_isready" --health-interval 5s --health-retries 10
$ trivy image myapp:1.0 --severity HIGH,CRITICAL --exit-code 1 # fail the build on serious CVEs $ trivy fs . ; gitleaks detect ; semgrep --config auto . $ pre-commit install # run checks before each commit, locally
"Protected main, layered tests against real services, and security scans as required checks."
# deploy job: runs only on main, uses an environment with approvals
deploy:
needs: [test, scan]
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
environment: production # require a reviewer in repo settings
permissions: { id-token: write, contents: read } # OIDC: no long-lived cloud keys
steps:
- uses: actions/checkout@v4
- uses: docker/login-action@v3
with: { registry: ghcr.io, username: "${{ github.actor }}", password: "${{ secrets.GITHUB_TOKEN }}" }
- uses: docker/build-push-action@v6
with: { push: true, tags: "ghcr.io/${{ github.repository }}:${{ github.sha }}" }
- run: kubectl set image deploy/web web=ghcr.io/${{ github.repository }}:${{ github.sha }}
- run: kubectl rollout status deploy/web --timeout=120s || kubectl rollout undo deploy/web
latest"Immutable image by SHA, canary with automated analysis, feature flags, and one-command rollback."
# ansible/site.yml
- hosts: web
become: true
tasks:
- name: Install nginx
ansible.builtin.apt: { name: nginx, state: present, update_cache: true }
- name: Deploy config
ansible.builtin.template: { src: nginx.conf.j2, dest: /etc/nginx/nginx.conf, mode: "0644" }
notify: reload nginx
- name: Ensure running
ansible.builtin.service: { name: nginx, state: started, enabled: true }
handlers:
- name: reload nginx
ansible.builtin.service: { name: nginx, state: reloaded }
$ ansible-playbook -i inventory.ini site.yml --check --diff # dry run: what would change? $ ansible-playbook -i inventory.ini site.yml $ terraform fmt -check && terraform validate && terraform plan -out tf.plan $ terraform apply tf.plan $ packer build image.pkr.hcl # bake a machine image
"Terraform for resources, baked images over in-place patching, idempotent playbooks, and a scheduled plan to detect drift."
# argocd Application: "keep this cluster path in sync with that git path"
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata: { name: web, namespace: argocd }
spec:
project: default
source: { repoURL: https://github.com/acme/deploy-config, targetRevision: main, path: apps/web/prod }
destination: { server: https://kubernetes.default.svc, namespace: web }
syncPolicy:
automated: { prune: true, selfHeal: true } # remove deleted resources, undo manual drift
syncOptions: [CreateNamespace=true]
$ kubectl kustomize apps/web/prod | kubectl diff -f - # preview a change $ argocd app sync web ; argocd app history web ; argocd app rollback web 12 $ helm template web ./chart -f values-prod.yaml | kubectl apply --dry-run=server -f - # CI's last step: bump the image tag in the config repo (a commit), instead of running kubectl directly
"GitOps: CI updates the config repo, Argo reconciles the cluster, and a rollback is a git revert."
# docker-compose.monitoring.yml (local stack: metrics + dashboards)
services:
prometheus:
image: prom/prometheus
volumes: ["./prometheus.yml:/etc/prometheus/prometheus.yml"]
ports: ["9090:9090"]
grafana:
image: grafana/grafana
ports: ["3001:3000"]
# alert rule: users are seeing errors
- alert: HighErrorRate
expr: sum(rate(http_requests_total{status=~"5.."}[5m])) / sum(rate(http_requests_total[5m])) > 0.02
for: 5m
labels: { severity: page }
annotations: { runbook: "https://wiki.acme/runbooks/high-5xx", summary: "5xx > 2%" }
"Alerts on SLO burn with runbooks attached, mitigate before diagnosing, and blameless reviews that produce tracked fixes."
$ gitleaks protect --staged # pre-commit: block secrets $ trivy fs --scanners vuln,secret,misconfig . # deps, secrets, IaC in one go $ trivy image --severity HIGH,CRITICAL --exit-code 1 myapp:1.0 $ checkov -d infra/ # Terraform/K8s misconfigurations $ syft myapp:1.0 -o spdx-json > sbom.json # software bill of materials $ cosign sign --yes ghcr.io/acme/myapp@sha256:… # sign the image $ cosign verify ghcr.io/acme/myapp@sha256:… --certificate-identity-regexp '.*' --certificate-oidc-issuer https://token.actions.githubusercontent.com
"Secrets, dependency, image and IaC scans gate the build, artifacts are signed with an SBOM, and the cluster only admits signed images."
Dockerfile. Run it locally.destroy).$ make help # give humans and CI the same entry points .PHONY: test build deploy test: ; npm ci && npm test build: ; docker build -t myapp:$(shell git rev-parse --short HEAD) . deploy: ; ./scripts/deploy.sh $(ENV)
"Small changes, automated checks, immutable artifacts, GitOps promotion, and monitoring that tells us before users do."