Skip to content

The defense ​

The thread of the Part One defense, in the order the subject asks for. Each part says who presents, what to show, and links to the details in these docs.

The projected presentation

Open the presentation: arrows ← → to navigate, F for full screen, N for the speaker notes.

#PartPresented by
1The need and the sampleElias
2Technical choiceseach their own brick
3The repository and the environmentsElias
4The APIPatrice
5The front endJean-Baptiste
6The pipelineElias
7The runnersElias
8Secrets securityElias
9The demoElias, with the team
10The bonusesElias

1. The need and the sample ​

“There should be two tasks for a human being to perform to deploy software: to pick the version and environment and to press the deploy button.”

— David Farley, Continuous Delivery, quoted by the subject

In our project:

The taskWhat it is
Pick the versionthe commit: each image carries its SHA
Pick the environmentthe branch: develop → dev, main → prod
Press the buttonthe merge request's merge, or Re-deploy to go back

The sample is the back office of a grocery chain: one page that lists, adds and deletes products.

Online: https://trinity.jostud.com, https://dev.trinity.jostud.com and these docs at https://docs.trinity.jostud.com.

2. Technical choices ​

NeedChoiceWhy
APIDjango + Django REST Framework, GunicornPatrice's strength; a full CRUD in a few lines
WebNext.js, server-side renderingJean-Baptiste's strength; the API address stays on the server
DatabasePostgreSQL 17standard, official image
CI/CDGitLab CI + self-hosted runnersasked by the subject; the jobs run on our machines
ContainersDocker: Compose in dev, Swarm in prodSwarm gives zero downtime and rollback with no home-made script
Traffic entryTraefik v3.6 + Let's Encryptautomatic HTTPS, one route per file
Servers2 Google Cloud VMs, configured by Ansibledev isolated from prod; replayable configuration

Key point: the code tools are the ones the team masters, to keep the time for DevOps, which is what is graded. Details: Technical choices.

3. The repository and the environments ​

One GitLab repository, one part per folder:

trinity-devops/
├── .gitlab-ci.yml        the root pipeline
├── api/                  Django, Dockerfile.dev, Dockerfile.prod, its CI jobs
├── web/                  Next.js, Dockerfile.dev, Dockerfile.prod, its CI jobs
├── docs/                 these docs (VitePress)
└── infra/
    ├── ansible/          4 roles: docker, ufw, traefik, gitlab-runner
    ├── traefik/          configuration and dev / prod routes
    ├── docker-compose.dev.yml
    └── docker-compose.prod.yml
  • develop and main are protected: no direct push, everything goes through a merge request.
  • GitLab copies the repository to the school's GitHub on every push (mirror).
DevProd
Machinetrinity-dev (e2-medium)trinity-prod (e2-small)
Started withdocker compose up --builddocker stack deploy (Swarm)
Imagesbuilt on the spot, Dockerfile.devpulled from the registry: api:<sha>, web:<sha>, docs:<sha>
Serversrunserver, next devGunicorn, node server.js
Containersroot, DEBUG=Truenon-root, DEBUG=False, health check
Updateshort outagezero downtime, automatic rollback

Details: Dev and prod environments, Overall architecture.

4. The API ​

Presented by Patrice.

TopicTo show
Structurethe products app: model, serializer, ModelViewSet; /api/products/ as a CRUD; /health for the probes
DevDockerfile.dev: one stage, runserver, migrations run by Compose
ProdDockerfile.prod: two stages, Gunicorn with 3 workers, appuser user, health check; entrypoint.sh runs migrate and collectstatic
Tests7 pytest-django tests, JUnit report and coverage visible in the merge request; flake8 at lint

Details: API overview.

5. The front end ​

Presented by Jean-Baptiste.

TopicTo show
Structurethe page is rendered on the server; adding and deleting go through Server Actions; the browser never talks to the API directly
DevDockerfile.dev: next dev
ProdDockerfile.prod: three stages, standalone build, node server.js, nextjs user, health check on /api/health
Tests18 Jest and Testing Library tests, JUnit report and coverage; ESLint at lint

Details: Web front end overview.

6. The pipeline ​

Push tolint and testimage builddeployment
feature/*if the folder changednono
developif the folder changedyes, every timedev
mainif the folder changedyes, every timeprod

The points to make:

  • Each part has its own jobs file (api/.gitlab-ci.yml, web/.gitlab-ci.yml, docs/.gitlab-ci.yml), included by the root file: everyone moves forward without touching the others' jobs.
  • Tests are readable: JUnit reports in the Tests tab and coverage in the merge request.
  • Each deployment checks itself: curl on /health through Traefik and HTTPS. In prod, the job also checks that Swarm runs the commit's images, or it fails.

Details: The pipeline, From a commit to prod.

7. The runners ​

RunnerMachineExecutorTagRuns
trinity-dev-runnertrinity-devdocker, privilegednonelint, tests, builds
trinity-dev-deploytrinity-devshelldevdeploy-dev
trinity-prod-deploytrinity-prodshellproddeploy-prod

The proof of connection, to show in this order:

  1. GitLab, Settings > CI/CD > Runners: the three runners are online, and GitLab's shared runners are disabled.
  2. A finished job: the first line of the log names the runner, for example on trinity-dev-runner.
  3. The simple test: a merge request touching api/ runs api:lint and api:test on our runner.

To say: the runners are installed and registered by Ansible, with their tokens in the Vault. They fetch work from GitLab: no connection comes into the servers, and no deployment SSH key exists.

Details: Runners.

8. Secrets security ​

MeasureHow
No secret in the repositorydatabase passwords and the Django key in GitLab CI/CD variables: masked, protected, hidden, one value per environment
Runner tokensencrypted in Ansible Vault, password passed on outside Git
No deployment keythe deploy runners run on their server and call GitLab
Containersprod runs non-root; only Traefik publishes ports; the database is only on an internal network
NetworkGoogle Cloud firewall then UFW: 22, 80, 443; SSH key only
TransportHTTPS everywhere, Let's Encrypt certificates, 80 → 443 redirect
Branchesdevelop and main protected: only merges trigger a deployment

Details: Secrets and access, Flow matrix, Infrastructure.

9. The demo ​

Tabs to open beforehand: GitLab (Pipelines, Operate > Environments), the prod site, the dev site, Datadog, and a terminal.

  1. A small change on a feature/* branch, then a merge request to develop: lint and tests pass, the test report shows in the merge request.

  2. The merge into develop: builds, then deploy-dev. Show the change on https://dev.trinity.jostud.com.

  3. Start the counter in the terminal, and leave it running until the end:

    sh
    u=https://trinity.jostud.com/api/health; ok=0; ko=0
    while true; do
      c=$(curl -s -m 5 -o /dev/null -w "%{http_code}" $u)
      [ "$c" = 200 ] && ok=$((ok+1)) || ko=$((ko+1))
      printf "\rOK: %d   errors: %d" $ok $ko; sleep 0.2
    done
  4. The merge into main: deploy-prod replaces the containers one at a time. The error counter stays at 0.

  5. The rollback: Operate > Environments > prod, Re-deploy button on the previous deployment. Prod goes back to the old version, still without errors.

  6. Datadog: the demo's pipeline and the duration of each stage.

Before the demo

Do a full rehearsal the day before: the develop then main pipelines take about 15 minutes each. Have the merge request to main already open.

10. The bonuses ​

Load balancer ​

In prod, the API and the web run as two instances. Traefik sends requests to the Swarm service, which spreads them between its tasks. An update replaces the tasks one at a time. Details: Zero-downtime deployment.

Pipeline monitoring ​

The GitLab → Datadog CI Visibility integration sends every pipeline and every job: duration, status, stage by stage. No agent to install: the API key is stored, encrypted, in the GitLab integration.

A develop pipeline seen in Datadog: 13 min 52 in total, the build stage takes 7 min 37

What Datadog showed: the hatched parts are waiting. The CI runner runs one job at a time (concurrent = 1), so docs:build waits 6 min 38 before starting. It is the simplest improvement to shorten the pipeline.

Log persistence ​

Not done: the logs stay in the containers. See Limits and improvements.

Extras ​

The numbers to remember ​

NumberWhat it measures
0 errors in 1,268 requestsa real prod release, measured during the deployment
13 min 52a full develop pipeline, according to Datadog
about 1 minthe deploy-prod job
25 tests7 for the API, 18 for the web
3 runnerson 2 VMs, no GitLab shared runner
566 → 283 MBthe API dev image, after the cleanup

Likely questions ​

QuestionShort answer
Why Swarm and not Kubernetes?Swarm is built into Docker: zero downtime, rollback and load balancing in a few lines. Kubernetes is oversized for one VM
Why a runner on each server rather than a job that connects over SSH?No SSH key to store at GitLab, and nothing comes into the servers
What if the new version is broken?Its health check fails, Swarm keeps the old one, and the job fails: the pipeline turns red
Where are the passwords?In the GitLab variables, masked and protected, injected at deployment; never in a file
Why does dev rebuild its images?To test the code in development mode; prod uses the images built once by the pipeline
How to go back to a previous version?Environments > prod > Re-deploy: each commit's images stay in the registry
Why two VMs?An error or a load spike in dev never touches prod
What is missing?Automatic secret scanning, database backup, log persistence, a second node. See Limits