Every team starts with the same deployment process:
- Write code on your laptop.
- Zip it up.
- SSH into the server.
- Cross your fingers and pray.
- Something breaks in production at 2 AM.
CI/CD exists to make Step 3–5 automatic, repeatable, and less terrifying.
This is the Mastery Guide to CI/CD. We’ll use the “Factory Assembly Line” model to understand pipelines, GitHub Actions, and the art of zero-downtime deployments.
Part 1: Foundations (The Mental Model)
The Old Way: Artisan Crafting
In a blacksmith shop, one guy does everything: heats the metal, shapes it, cools it, inspects it, packages it. If he’s sick, nothing ships. If he makes a mistake, it goes to the customer.
This is manual deployment.
The New Way: The Factory Assembly Line
A modern factory has stations: Stamping → Welding → Painting → Inspection → Packaging. Each station checks the output of the previous one. If Inspection fails, nothing reaches Packaging.
This is CI/CD:
| |
Part 2: The Investigation (GitHub Actions Anatomy)
GitHub Actions is the most popular CI/CD tool for developers. A “workflow” is just a YAML file in .github/workflows/.
Reading a Pipeline
| |
Key Concepts to Spot:
on:— The trigger. (push,pull_request,schedule).jobs:— Independent units of work that CAN run in parallel.needs:— Creates a dependency (Job B waits for Job A).secrets:— Secrets stored in GitHub settings. Never hardcode passwords in YAML!
Part 3: The Diagnosis (Common Failures)
The “Works in CI, Fails in Production” Mystery
| Problem | Cause | Fix |
|---|---|---|
| Different dependencies | CI installs fresh. Production has leftovers. | Docker everything. Immutable artifacts. |
| Different environment variables | CI has DEBUG=True. Prod doesn’t. | Use env: in GitHub Actions and match production secrets. |
| Database migrations forgot | Code deployed, migration not run. | Add a migration step BEFORE the deploy step. |
| Tests pass but app crashes | Tests don’t cover the startup code. | Add a smoke test: curl http://localhost:8000/health after deploy. |
Part 4: The Resolution (Deployment Strategies)
Not all deployments are equal. The strategy determines the risk.
Strategy 1: Rolling Deployment (Kubernetes Default)
Replace old pods one by one. Minimal risk. If one fails, stop.
Strategy 2: Blue/Green Deployment (Zero Downtime)
Run TWO identical production environments. “Blue” is live. “Green” is the new version.
| |
- Benefit: Instant rollback. If Green fails, flip the switch back to Blue.
- Cost: Requires double the infrastructure.
Strategy 3: Canary Deployment (Progressive)
Slowly roll out to a percentage of users. If no errors, increase to 100%.
| |
Final Mental Model
| |
Rules for Good CI/CD:
- Fast feedback: The pipeline should fail in under 5 minutes if there’s a problem.
- Everything is code: The pipeline config is in Git. No clicking in Jenkins UI.
- Immutable artifacts: Build once, deploy the same image everywhere. Never
git pullon a production server.
