In a nutshell: You automate the verification and the delivery of your code with GitHub Actions. On every push, a pipeline checks the code (lint), runs the tests, builds Docker images and pushes them to Docker Hub — without any human intervention.
In Module 3, you learned how to build Docker images and run them with docker compose. But who builds those images when you push your code? Who checks that the tests pass? Who pushes the images to Docker Hub? That’s the role of CI/CD — automating all of that.
The problem: Without CI/CD, every deployment is manual. Someone runs the tests on their machine, someone else does the build, a third person deploys via SSH. It’s slow, risky, and a source of human error. “I forgot to run the tests before deploying” — boom, production is broken.
It’s the difference between baking each pizza by hand and having an automated oven with a conveyor belt.
CI (Continuous Integration): On every push, we automatically check that the code is clean (lint) and that it works (tests). We don’t wait until the night before delivery to find out it’s broken.
CD (Continuous Delivery / Deployment):
Delivery = the code is ready to be deployed (manual button)
Deployment = the code is deployed automatically if everything is green
The analogy: An assembly line in a factory. You push the raw material (the code) onto the conveyor belt. Station 1 = quality control (lint). Station 2 = taste test (tests). Station 3 = packaging (build). Station 4 = dropping off at the depot (push). Station 5 = delivery to the customer (deploy). If a defect is detected at any station, the line stops. This is the “fail fast” principle.
Checks code style and quality (syntax errors, unused variables, bad practices) — like a spell checker for code
Spell checker
Ruff (Python), Oxlint (JS)
Test
Checks that the code does what it should
Tasting the dish
Pytest
Build
Compiles/packages the application
Packaging the dish
Docker build
Push (delivery)
Publishes the image to a registry — the parcel is ready to ship
Dropping the parcel off at the depot
docker push (Docker Hub)
Deploy (deployment)
Puts the code in production — the parcel arrives at the customer
Delivering to the customer
SSH + docker compose (Modules 6-7)
These stages run in sequence. If lint fails, no tests. If tests fail, no build. Fail fast.
⚠️ Delivery ≠ deployment. Pushing an image to Docker Hub (push) puts nothing in production: it just publishes a ready-to-use artifact. The Deploy stage is what actually installs the new version on the server.
📍 In this module we stop at delivery (push). At this point you don’t have a server yet — and that’s expected: it arrives in Module 6, when Terraform creates a real one for you. That’s where we’ll write the deploy job and wire this pipeline up to your server.
A YAML file in .github/workflows/ describes the pipeline. Here’s a minimal example with each line explained:
# .github/workflows/ci.yml <- the file must be in this exact folder
name: CI Pipeline# The name shown in GitHub's Actions tab
on: # "on" = WHEN does this pipeline trigger?
push: # -> when someone pushes code
branches: [main] # -> but only on the "main" branch
pull_request: # -> OR when a Pull Request is created/updated
branches: [main] # -> targeting the "main" branch
jobs: # The list of jobs (groups of steps) to run
lint: # The job name (you choose whatever name you want)
runs-on: ubuntu-latest# On which machine to run? -> an Ubuntu server provided by GitHub
steps: # The list of steps for this job
- uses: actions/checkout@v4# "uses" = use a pre-made action by someone else
# "actions/checkout" = an official GitHub action that downloads
# your code onto the runner (otherwise the runner is empty, it doesn't have your code)
# "@v4" = version 4 of this action
- name: Setup uv# "name" = a readable name for this step (shown in the UI)
uses: astral-sh/setup-uv@v4# Installs uv on the runner (like you did on your machine)
- run: cd backend && uv run ruff check .
# "run" = execute a bash command directly
# (unlike "uses" which calls a pre-made action)
In a nutshell — the 4 keywords to remember:
Keyword
What it does
Example
on:
When the pipeline triggers
on: push = on every push
runs-on:
On which machine
ubuntu-latest = a free Ubuntu server from GitHub
uses:
Use a pre-made action
actions/checkout@v4 = download the code
run:
Execute a bash command
run: uv run pytest = run the tests
uses vs run:uses calls a “plugin” (a ready-to-use action written by someone else — install Python, log in to Docker Hub, etc.). run executes a bash command that YOU write. If an action exists for what you want to do, use uses. Otherwise, run.
What does “4 deselected” mean? The project contains two families of tests, and pytest only runs one of them by default.
Unit tests
Integration tests
They test
Your code on its own
Your code together with the services it talks to
They need
Nothing
A database, a server, an external service…
Duration
Milliseconds
Seconds
When
On every save, continuously
On every push, in CI
Why both? Remember Module 3: your main.py has two modes. Without DATABASE_URL it stores tasks in a Python list; with DATABASE_URL it talks to PostgreSQL.
But uv run pytest runs without DATABASE_URL. So all the PostgreSQL code — half of main.py — is never executed by the tests. If it contained a typo in a SQL query, no test would catch it: it would only break in production.
That’s exactly the hole the rest of this module fills.
Integration tests carry a marker (@pytest.mark.integration), and pyproject.toml asks pytest to skip them by default. That’s deliberate: fast tests must be runnable with nothing installed, otherwise developers stop running them.
The ones in test_integration.py need cloud services — we’ll switch them on in Module 5. Nothing to do with them for now.
A service container is a container GitHub starts before your steps, that runs alongside them, and that it stops afterwards. Your tests reach it on localhost. It’s the equivalent of Module 3’s docker compose up, but managed by GitHub — and thrown away at the end of the job.
Here is the integration-test job from the provided .github/workflows/ci.yml:
integration-test:
name: Integration Test
runs-on: ubuntu-latest
needs: lint
services:
# A real PostgreSQL database, for the duration of the job
postgres:
image: postgres:16
env:
POSTGRES_USER: user
POSTGRES_PASSWORD: pass
POSTGRES_DB: tasks
ports:
- 5432:5432
# Without health-cmd, the tests would start BEFORE PostgreSQL is
# ready to answer, and fail for the wrong reason.
options: >-
--health-cmd "pg_isready -U user -d tasks"
--health-interval 5s
--health-timeout 3s
--health-retries 10
steps:
- uses: actions/checkout@v4
- name: Setup uv
uses: astral-sh/setup-uv@v4
# The SAME tests as the `test` job, but against a real database.
# The application code doesn't change: only DATABASE_URL appears.
💡 If docker run prints port is already allocated: another program holds the port you picked. Choose a different one (-p 55433:5432) and adjust the DATABASE_URL accordingly.
The same 7 tests pass in both modes. The code didn’t change by a single line — only an environment variable appeared.
1. --health-cmd isn’t decoration. “The container is started” ≠ “the service answers”. PostgreSQL takes one to three seconds to boot. Without a health check, your tests start too early and fail one time in three — the worst kind of test, the one that fails at random (a flaky test). It’s a very common source of CI incidents.
2. The same code, two configurations. The test job runs the tests in memory; integration-test runs exactly the same ones against PostgreSQL. That’s what proves a codebase is properly configurable — the same idea as Module 3’s depends_on: the configuration changes, the code doesn’t.
3. A throwaway environment on every run. The database is created empty at the start of the job and destroyed at the end. No test can pollute the next one, and no pipeline can disturb another.
4. Jobs run in parallel.test and integration-test both depend on lint, but not on each other: GitHub runs them at the same time. A pipeline isn’t necessarily a straight line — anything independent should run simultaneously.
There’s a third job in the file, called aws-test. It applies exactly the same principle, but to cloud services (S3, SQS) instead of a database. We’ll switch it on in Module 5, once we’ve seen what AWS is — no need to worry about it now.
The ci.yml file is already in the project. If you’ve pushed everything, the pipeline runs automatically.
⚠️ Check that it’s really there (remember the hidden-file copy in Module 0):
Fenêtre de terminal
ls-a~/devops-project/.github/workflows/
# ci.yml
If it’s missing, restore it: cp -r devops-from-zero/devops-project/.github ~/devops-project/ — without it, the Actions tab stays empty and nothing will trigger.
Fenêtre de terminal
cd~/devops-project
gitadd.
gitcommit-m"ci: pipeline GitHub Actions"
gitpush
Go to the Actions tab of your GitHub repo. You’ll see the pipeline running: Lint -> Test -> Build -> Push.
💡 If the Docker Hub push fails: check that the secrets are properly configured. The push job only runs on the main branch (not on pull requests).
Q: What is CI/CD?
A: CI = automatically checking code on every push (lint, tests). CD = automatically deploying if everything passes. It reduces human errors and speeds up deliveries.
Q: What are the stages of a typical CI/CD pipeline?
A: Lint (code quality) -> Tests -> Build (artifact construction) -> Push (publishing the image to a registry) -> Deploy (putting it in production). Each stage blocks the next one if it fails.
Q: What is “fail fast”?
A: If a stage fails, everything stops immediately. No need to build if the tests don’t pass. It saves time and resources.
Q: What’s the difference between delivering (pushing) an image and deploying it?
A: Pushing an image to Docker Hub makes it available, but changes nothing about what’s running in production. Deploying means installing that new version on the server and restarting the app. You can deliver on every push and only deploy after validation.
Q: Where should you store secrets in a pipeline?
A: In the CI/CD secrets (GitHub Secrets, GitLab Variables, etc.). Never in the code, never in committed YAML files.
Q: Difference between Continuous Delivery and Continuous Deployment?
A: Delivery = ready to deploy but manual button. Deployment = automatic deployment. Most companies do Delivery.
Q: What is a runner?
A: The machine (server) that runs the pipeline’s jobs. GitHub provides free runners (ubuntu-latest). You can also use your own runners.
Q: What is a blue/green deployment?
A: A deployment strategy with two identical environments. “Blue” serves production, you deploy the new version to “green”, test it, then switch the traffic. If it breaks, you switch back in seconds. Advantage: instant rollback.
Q: What is a canary deployment?
A: You deploy the new version to a small percentage of servers (e.g., 5%). You monitor the metrics. If everything’s fine, you gradually increase (25% → 50% → 100%). If it breaks, only 5% of users are impacted.
The pipeline must be fast. If the CI takes 20 min, devs stop using it. Parallelize independent jobs (lint backend || lint frontend), use caching (dependencies, Docker images).
Fail fast. Put the fastest stages first (lint < tests < build < deploy). No need to build for 5 min if lint fails in 10 seconds.
Never put secrets in the code. Use CI secrets (GitHub Secrets, GitLab Variables). If a secret was committed by mistake, change it immediately — a git rm is not enough (the history keeps everything).
A pipeline per branch, not just main. Run CI on Pull Requests too. The goal is to know if the code is broken BEFORE merging.
Reproducibility. Pin your action versions (actions/checkout@v4, not @latest). A pipeline that breaks on its own because a dependency was updated is a nightmare.
No git push --force from CI. CI should never destructively modify the source branch.
Automatic rollback: watch health after deployment and go back on your own if it breaks (healthchecks, kubectl rollout undo)
ArgoCD (GitOps): the Git repo IS the source of truth for deployment. You push YAML, ArgoCD deploys automatically on K8s (requires having done Module 9 — Kubernetes)