feat: dockerisation frontend Next.js (output: standalone)

- next.config.mjs : output: 'standalone' — bundle minimal sans node_modules
- Dockerfile      : multi-stage (deps → builder → runner) sur node:22-alpine
  - ARG build-time pour les vars NEXT_PUBLIC_* et SENTRY_AUTH_TOKEN (optionnel)
  - Utilisateur non-root nextjs:nodejs (uid/gid 1001)
  - Image finale < 200 Mo (pas de node_modules, juste .next/standalone)
- docker-compose.yml : service frontend avec env_file et restart: unless-stopped
- .dockerignore   : exclut node_modules, .next, .env, yarn.lock, docs

Alternative au déploiement PM2 existant (DEPLOYMENT.md inchangé).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-14 06:55:41 +04:00
parent c4762c6437
commit e75d2e1c53
5 changed files with 77 additions and 1 deletions
+9
View File
@@ -0,0 +1,9 @@
Dockerfile
.dockerignore
node_modules
.next
.git
.env
yarn.lock
tasks/
*.md
+52
View File
@@ -0,0 +1,52 @@
# ─── Étape 1 : dépendances ───────────────────────────────────────────────────
FROM node:22-alpine AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
# ─── Étape 2 : build de production ───────────────────────────────────────────
FROM node:22-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Variables nécessaires au build (publiques uniquement — pas de secrets)
ARG NEXT_PUBLIC_DIRECTUS_API_URL
ARG NEXT_PUBLIC_DIRECTUS_API_WS_URL
ARG NEXT_PUBLIC_SENTRY_DSN
ARG SENTRY_AUTH_TOKEN
ENV NEXT_PUBLIC_DIRECTUS_API_URL=$NEXT_PUBLIC_DIRECTUS_API_URL
ENV NEXT_PUBLIC_DIRECTUS_API_WS_URL=$NEXT_PUBLIC_DIRECTUS_API_WS_URL
ENV NEXT_PUBLIC_SENTRY_DSN=$NEXT_PUBLIC_SENTRY_DSN
ENV SENTRY_AUTH_TOKEN=$SENTRY_AUTH_TOKEN
RUN npm run build
# ─── Étape 3 : image de production minimale ──────────────────────────────────
FROM node:22-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV PORT=3000
ENV HOSTNAME=0.0.0.0
# Utilisateur non-root pour la sécurité
RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 nextjs
# Le mode standalone copie uniquement ce qui est nécessaire à l'exécution
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
USER nextjs
EXPOSE 3000
# server.js généré par output: 'standalone'
CMD ["node", "server.js"]
+13
View File
@@ -0,0 +1,13 @@
services:
frontend:
build:
context: .
args:
NEXT_PUBLIC_DIRECTUS_API_URL: ${NEXT_PUBLIC_DIRECTUS_API_URL}
NEXT_PUBLIC_DIRECTUS_API_WS_URL: ${NEXT_PUBLIC_DIRECTUS_API_WS_URL}
NEXT_PUBLIC_SENTRY_DSN: ${NEXT_PUBLIC_SENTRY_DSN}
# SENTRY_AUTH_TOKEN: ${SENTRY_AUTH_TOKEN} # décommenter pour uploader les source maps
ports:
- "3000:3000"
env_file: .env
restart: unless-stopped
+2
View File
@@ -53,6 +53,8 @@ const securityHeaders = [
] ]
const nextConfig = { const nextConfig = {
// Active le mode standalone : bundle minimal autonome pour Docker
output: 'standalone',
experimental: { experimental: {
// Optimiser les imports pour réduire la mémoire // Optimiser les imports pour réduire la mémoire
optimizePackageImports: ['@mui/material', '@mui/icons-material', '@emotion/react', '@emotion/styled'], optimizePackageImports: ['@mui/material', '@mui/icons-material', '@emotion/react', '@emotion/styled'],
+1 -1
View File
@@ -20,7 +20,7 @@
## Améliorations moyennes (P3) ## Améliorations moyennes (P3)
- [x] ISR page d'accueil (`revalidate`) - [x] ISR page d'accueil (`revalidate`)
- [ ] Dockerisation frontend (`output: standalone`) - [x] Dockerisation frontend (`output: standalone`)
- [ ] Audit accessibilité WCAG 2.1 - [ ] Audit accessibilité WCAG 2.1
- [ ] Responsive mobile dashboard - [ ] Responsive mobile dashboard
- [ ] Lazy loading jsPDF + md-editor - [ ] Lazy loading jsPDF + md-editor