Trinity

Trinity

From merge to prod, with no manual step and no downtime.

Patrice · APIJean-Baptiste · WebElias · DevOps

Part 1 · Elias

Two gestures to deploy

“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

Version

the commit

Environment

the branch

Button

the merge

trinity.jostud.com
The Products page: add form and table of products with their stock status

Part 2 · The whole team

Tools we master, time for DevOps

NeedChoiceWhy
APIDjango + DRF, GunicornPatrice's strength, a fast CRUD
WebNext.js, server renderingJean-Baptiste's strength
DatabasePostgreSQL 17standard, official image
CI/CDGitLab CI, our own runnersasked by the subject, jobs on our VMs
ContainersCompose in dev, Swarm in prodzero downtime and rollback, no script
EntryTraefik + Let's Encryptautomatic HTTPS, one route per file
Servers2 Google Cloud VMs + Ansibledev isolated from prod, replayable config

Part 3 · Elias

A monorepo, protected branches

trinity-devops/ ├── .gitlab-ci.yml root pipeline ├── api/ Django ├── web/ Next.js ├── docs/ VitePress └── infra/ ├── ansible/ 4 roles + Vault ├── traefik/ dev / prod routes ├── docker-compose.dev.yml └── docker-compose.prod.yml

feature/*

lint + tests

↓

develop

deploy → dev

↓

main

deploy → prod

Part 3 · Elias

Two VMs, two ways to run

GITLAB.COM

Repo + pipelines
Registry

→ GitHub mirror
→ Datadog
The runners call it: nothing comes into the VMs

DEV · DEVELOP · COMPOSE

Traefik · 80 / 443
web
api
db
CI runner
deploy runner

Images built on the spot
Update: short outage

PROD · MAIN · SWARM

Traefik · 80 / 443
web × 2
api × 2
docs
db
deploy runner

Images from the registry: api:<sha>
Update: no downtime, auto rollback

Part 4 · Patrice

Django REST and PostgreSQL

Structure

  • products app: model, serializer, ViewSet
  • /api/products/ as a CRUD
  • /health for the probes

Dev → prod

  • Dev: runserver, one stage
  • Prod: two stages, Gunicorn
  • appuser non-root, health check
  • migrate + collectstatic at startup

Tests

  • 7 pytest-django tests
  • JUnit report and coverage in the MR
  • flake8 at lint

Part 5 · Jean-Baptiste

Next.js, server-side rendering

Structure

  • Page rendered on the server
  • Add and delete through Server Actions
  • The browser never talks to the API

Dev → prod

  • Dev: next dev
  • Prod: three stages, standalone build
  • nextjs non-root, health check

Tests

  • 18 Jest and Testing Library tests
  • JUnit report and coverage
  • ESLint at lint

Part 6 · Elias

Four stages, triggered by the branch

push

any
branch

→

lint

api:lint
web:lint

→

test

api:test
web:test

→

build

api, web,
docs

→

deploy

deploy-dev
deploy-prod

Push tolint and testbuilddeployment
feature/*if the folder changednono
developif the folder changedyesdev
mainif the folder changedyesprod

Each deployment checks itself: curl on /health, and in prod the 3 services must run the commit's image.

Part 7 · Elias

Three runners, on our two VMs

RunnerMachineExecutorTagRuns
trinity-dev-runnerdevdocker, privilegednonelint, tests, builds
trinity-dev-deploydevshelldevdeploy-dev
trinity-prod-deployprodshellproddeploy-prod

Installed by Ansible, tokens in the Vault. They call GitLab: no deployment SSH key. GitLab shared runners disabled.

Part 8 · Elias

No secret in the repository

GitLab variables

Masked, protected, hidden, one value per environment

Ansible Vault

Runner tokens encrypted, password outside Git

No deployment key

The runners call GitLab, nothing comes in

Containers

Non-root in prod, only Traefik publishes ports

Network

GCP firewall + UFW: 22, 80, 443. SSH by key

HTTPS everywhere

Let's Encrypt, port 80 redirects to 443

Part 9 · Elias, with the team

From commit to prod, live

A merge request to develop: lint, tests, report

The merge into develop: deployment to dev

The request counter running against prod

The merge into main: prod changes, 0 errors

The rollback: Environments › prod › Re-deploy

The pipeline and its durations in Datadog

0

errors in 1,268 requests during a real prod release

Part 10 · Elias

Load balancer and monitoring

A develop pipeline in Datadog: 13 min 52 in total, build 7 min 37

Load balancer: two instances of the API and the web, Swarm spreads the requests

Monitoring: every pipeline and every job in Datadog, no agent

Also: the docs published by the pipeline, the GitHub mirror

Log persistence: not done

Thank you

Any questions?