Lesson 251 of 296
CI/CD, secrets and rollbacks
What you will learn
- Continuous integration, delivery and deployment
- A complete GitHub Actions pipeline
- Environments, approvals and secrets
- OIDC instead of long-lived cloud keys
- Deployment strategies: rolling, blue-green and canary
- Rollbacks and database migrations in pipelines
On this page
Definitions
| Term | Meaning |
|---|---|
| Continuous integration (CI) | Every push and pull request is automatically built and tested; developers merge small changes often |
| Continuous delivery | Every change that passes CI is ready to release; deploying to production is a button press (often with approval) |
| Continuous deployment | Every change that passes is deployed to production automatically |
Benefits: bugs found within minutes, small low-risk releases, no "works on my machine", a repeatable path to production.
A GitHub Actions pipeline
GitHub Actions runs workflows (YAML files in .github/workflows/) on events (push, pull request, schedule). A workflow has jobs; jobs have steps; steps run commands or reusable actions.
name: ci-cd
on:
pull_request:
push:
branches: [main]
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:18-alpine
env:
POSTGRES_PASSWORD: test
ports: ["5432:5432"]
options: >-
--health-cmd "pg_isready -U postgres"
--health-interval 5s --health-timeout 3s --health-retries 10
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: 24
cache: npm
- run: npm ci
- run: npm run lint
- run: npm run typecheck
- run: npm test
env:
DATABASE_URL: postgres://postgres:test@localhost:5432/postgres
deploy:
needs: test
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
environment: production
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v7
- uses: aws-actions/configure-aws-credentials@v6
with:
role-to-assume: arn:aws:iam::123456789012:role/github-deploy
aws-region: eu-west-2
- run: ./scripts/deploy.sh "${{ github.sha }}"What it shows:
- Triggers: run tests on every pull request; deploy only from
main. permissions: least privilege for the workflow's own GitHub token.- Service containers: a real PostgreSQL for integration tests (Lesson 206).
needs: test: deploy only if tests pass.environment: production: GitHub environments can require manual approval and hold environment-specific secrets.id-token: write+configure-aws-credentials: OIDC login to AWS (below).- The image or release is tagged with the commit SHA, so every deployment is traceable to exact code.
The action version numbers (@v7, @v6) were the latest major versions at the time of writing; check for newer ones. Security-conscious teams pin actions to a full commit SHA.
Secrets
- Store secrets in the CI platform's encrypted secrets (
${{ secrets.STRIPE_KEY }}), never in the repository. GitHub masks them in logs. - In production, applications read secrets from a secrets manager (AWS Secrets Manager, SSM Parameter Store, Doppler, Vault) or the platform's injected environment variables.
- Rotate secrets regularly and immediately after a leak. If a secret is committed to Git, assume it is compromised: rotate it (deleting the commit is not enough; Git history and forks keep it). Enable secret scanning (GitHub push protection, gitleaks).
OIDC instead of long-lived keys
The old way stored an AWS access key in CI secrets: a permanent key that can leak. With OpenID Connect (OIDC), GitHub issues a short-lived signed token to each workflow run; AWS trusts GitHub's identity provider and exchanges the token for temporary credentials for a specific IAM role, restricted by conditions such as "only this repository and only the main branch". No stored keys at all.
Deployment strategies
| Strategy | How | Pros | Cons |
|---|---|---|---|
| Recreate | Stop the old version, start the new | Simple | Downtime |
| Rolling | Replace instances a few at a time | No downtime, no extra capacity | Old and new versions run together briefly; slower rollback |
| Blue-green | Run the new version (green) next to the old (blue); switch traffic at once | Instant switch and instant rollback | Double capacity during the switch |
| Canary | Send a small share of traffic (say 5%) to the new version, watch metrics, then increase | Limits the damage of a bad release | Needs good monitoring and traffic splitting |
| Feature flags | Deploy code switched off; turn features on separately (LaunchDarkly, Unleash, a config table) | Separates deploying from releasing; quick switch-off | Flag clean-up needed |
Rollbacks
- Keep previous images or artefacts; rollback = redeploy the previous tag (ECS keeps previous task definitions; Kubernetes has
rollout undo). - Automated rollback on failed health checks or alarms (ECS deployment circuit breaker, CodeDeploy alarms).
- Database migrations are the hard part: code can be rolled back, data changes often cannot. So make migrations backward-compatible using expand and contract (Lesson 228): the previous version of the code must still work with the new schema. Run migrations as a separate pipeline step before deploying the code that needs them.
- Smoke-test after deploying (call health and key endpoints) and watch error rates.
How to say it in an interview
"CI builds and tests every pull request; continuous delivery keeps main always releasable, and continuous deployment ships automatically. In GitHub Actions I run lint, type checks and tests with a real database service container on pull requests, and on main deploy through a protected environment with approval. I avoid long-lived cloud keys by using OIDC to assume a narrowly scoped IAM role, keep secrets in encrypted CI secrets and a secrets manager, and rotate anything that leaks. I deploy with rolling, blue-green or canary releases tagged by commit SHA, use feature flags to separate deploy from release, roll back by redeploying the previous image, and keep migrations backward-compatible with expand and contract."
Key words
| Word | Meaning |
|---|---|
| CI | Automatically building and testing every change |
| Continuous delivery / deployment | Always releasable / released automatically |
| Workflow / job / step | GitHub Actions building blocks |
| Environment (GitHub) | A deployment target with rules and secrets |
| OIDC | Short-lived identity tokens instead of stored keys |
| Rolling / blue-green / canary | Deployment strategies |
| Feature flag | A switch that turns code paths on or off at runtime |
| Rollback | Returning to the previous working version |
Now prove it
This lesson is complete when you pass the quiz and all three practice levels.