Configuration, tests, build
Environment variables
| Variable | Role | Dev value | Prod value |
|---|---|---|---|
API_URL | API address, as seen from the Next.js server | https://api.dev.trinity.jostud.com | https://api.trinity.jostud.com |
PORT | Listening port (prod image) | — | 3000 |
HOSTNAME | Listening interface (prod image) | — | 0.0.0.0 |
NEXT_TELEMETRY_DISABLED | Turns off Next.js telemetry | 1 | 1 |
WATCHPACK_POLLING | Detects changes through a Docker volume | true | — |
The committed example file:
sh
# Copier ce fichier en .env.local pour le développement en local.
# Les vraies valeurs de dev et de prod sont dans les variables CI/CD GitLab.
# URL de l'API Django, vue depuis le serveur Next.js (pas depuis le navigateur).
API_URL=http://localhost:8000Versions
| Tool | Version |
|---|---|
| Node.js (Docker image) | 22, Alpine |
| Next.js | 16.4.3 |
| React / React DOM | 19.3.1 |
| ESLint | 10.13.0, with eslint-config-next 16.4.3 |
| Jest | 30.5.2, with jest-junit 17.0.0 |
| Testing Library React | 16.3.3 |
The exact list is in web/package.json.
Tests
18 tests in 6 files. See Folder layout to know which file tests what.
sh
cd web
npm test # run the tests
npm run test:ci # + coverage + JUnit reporttest:ci produces two read by GitLab:
| File | Format | Shown in GitLab |
|---|---|---|
web/junit.xml | the Tests tab of the pipeline and the merge request | |
web/coverage/cobertura-coverage.xml | Cobertura | line-by-line in the diff |
The percentage shown on the job comes from the Lines : xx% line of the logs.
The two Dockerfiles
Dockerfile.dev | Dockerfile.prod | |
|---|---|---|
| Command | npm run dev (next dev) | node server.js |
| Stages | one | three: deps → builder → runner () |
| Dependencies | all, including ESLint and Jest | only those of the server |
| User | root | nextjs () |
| no | wget on /api/health every 10 s | |
| Used by | the dev server | the prod server |
docker
# Image de production en 3 étapes (multi-stage) : seule la dernière est
# gardée, elle ne contient ni le code source, ni les outils de build.
# 1. Installation des dépendances
FROM node:22-alpine AS deps
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
# 2. Build de l'application (génère .next/standalone)
FROM node:22-alpine AS builder
WORKDIR /app
ENV NEXT_TELEMETRY_DISABLED=1
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN npm run build
# 3. Image finale : uniquement le serveur autonome et les fichiers statiques
FROM node:22-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production \
NEXT_TELEMETRY_DISABLED=1 \
PORT=3000 \
HOSTNAME=0.0.0.0
# Utilisateur sans privilèges : si l'app est compromise, l'attaquant n'est pas root.
RUN addgroup -S nodejs && adduser -S nextjs -G nodejs
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
USER nextjs
EXPOSE 3000
# Docker marque le conteneur "healthy" seulement si /api/health répond.
HEALTHCHECK --interval=10s --timeout=3s --start-period=10s --retries=3 \
CMD wget -qO- http://127.0.0.1:3000/api/health || exit 1
CMD ["node", "server.js"]Pipeline jobs
They are defined in web/.gitlab-ci.yml, included by the root pipeline.
| Job | Stage | When | What it does |
|---|---|---|---|
web:lint | lint | on every push that changes web/ | npm run lint |
web:test | test | on every push that changes web/ | npm run test:ci, publishes the reports |
web:build | build | on every push to develop or main | builds Dockerfile.prod, pushes the image |
Images pushed to the :
registry.gitlab.com/epitech_gitlab/trinity-devops/web:<sha>: the exact version of a commit, used by prod;registry.gitlab.com/epitech_gitlab/trinity-devops/web:<branch>: the latest version ofdevelopormain.
yml
# Jobs du front web, inclus par le .gitlab-ci.yml racine (qui définit les stages).
# Chaque job ne se lance que si un fichier de web/ a changé.
.web:
image: node:22-alpine
before_script:
- cd web
- npm ci --cache .npm --prefer-offline
cache:
key:
files:
- web/package-lock.json
paths:
- web/.npm/
rules:
- changes:
- web/**/*
web:lint:
extends: .web
stage: lint
script:
- npm run lint
web:test:
extends: .web
stage: test
script:
- npm run test:ci
# GitLab extrait le pourcentage de la ligne "Lines : xx%" des logs.
coverage: '/Lines\s*:\s*(\d+(?:\.\d+)?)%/'
artifacts:
when: always
reports:
# Affiché dans l'onglet "Tests" du pipeline et dans la merge request.
junit: web/junit.xml
coverage_report:
coverage_format: cobertura
path: web/coverage/cobertura-coverage.xml
web:build:
stage: build
image: docker:27.5.1-cli
services:
- name: docker:27.5.1-dind
alias: docker
variables:
DOCKER_HOST: tcp://docker:2376
DOCKER_TLS_CERTDIR: /certs
DOCKER_TLS_VERIFY: "1"
DOCKER_CERT_PATH: "$DOCKER_TLS_CERTDIR/client"
before_script:
# Identifiants fournis automatiquement par GitLab, jamais écrits dans le repo.
- echo "$CI_REGISTRY_PASSWORD" | docker login "$CI_REGISTRY" --username "$CI_REGISTRY_USER" --password-stdin
script:
- docker build --pull --file web/Dockerfile.prod --tag "$CI_REGISTRY_IMAGE/web:$CI_COMMIT_SHORT_SHA" web
- docker push "$CI_REGISTRY_IMAGE/web:$CI_COMMIT_SHORT_SHA"
rules:
- if: '$CI_COMMIT_BRANCH == "develop" || $CI_COMMIT_BRANCH == "main"'