Skip to content

Configuration, tests, build ​

Environment variables ​

VariableRoleDev valueProd value
API_URLAPI address, as seen from the Next.js serverhttps://api.dev.trinity.jostud.comhttps://api.trinity.jostud.com
PORTListening port (prod image)—3000
HOSTNAMEListening interface (prod image)—0.0.0.0
NEXT_TELEMETRY_DISABLEDTurns off Next.js telemetry11
WATCHPACK_POLLINGDetects changes through a Docker volumetrue—

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:8000

Versions ​

ToolVersion
Node.js (Docker image)22, Alpine
Next.js16.4.3
React / React DOM19.3.1
ESLint10.13.0, with eslint-config-next 16.4.3
Jest30.5.2, with jest-junit 17.0.0
Testing Library React16.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 report

test:ci produces two read by GitLab:

FileFormatShown in GitLab
web/junit.xmlthe Tests tab of the pipeline and the merge request
web/coverage/cobertura-coverage.xmlCoberturaline-by-line in the diff

The percentage shown on the job comes from the Lines : xx% line of the logs.

The two Dockerfiles ​

Dockerfile.devDockerfile.prod
Commandnpm run dev (next dev)node server.js
Stagesonethree: deps → builder → runner ()
Dependenciesall, including ESLint and Jestonly those of the server
Userrootnextjs ()
nowget on /api/health every 10 s
Used bythe dev serverthe 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.

JobStageWhenWhat it does
web:lintlinton every push that changes web/npm run lint
web:testteston every push that changes web/npm run test:ci, publishes the reports
web:buildbuildon every push to develop or mainbuilds 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 of develop or main.
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"'