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:
@@ -0,0 +1,9 @@
|
||||
Dockerfile
|
||||
.dockerignore
|
||||
node_modules
|
||||
.next
|
||||
.git
|
||||
.env
|
||||
yarn.lock
|
||||
tasks/
|
||||
*.md
|
||||
+52
@@ -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"]
|
||||
@@ -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
|
||||
@@ -53,6 +53,8 @@ const securityHeaders = [
|
||||
]
|
||||
|
||||
const nextConfig = {
|
||||
// Active le mode standalone : bundle minimal autonome pour Docker
|
||||
output: 'standalone',
|
||||
experimental: {
|
||||
// Optimiser les imports pour réduire la mémoire
|
||||
optimizePackageImports: ['@mui/material', '@mui/icons-material', '@emotion/react', '@emotion/styled'],
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@
|
||||
## Améliorations moyennes (P3)
|
||||
|
||||
- [x] ISR page d'accueil (`revalidate`)
|
||||
- [ ] Dockerisation frontend (`output: standalone`)
|
||||
- [x] Dockerisation frontend (`output: standalone`)
|
||||
- [ ] Audit accessibilité WCAG 2.1
|
||||
- [ ] Responsive mobile dashboard
|
||||
- [ ] Lazy loading jsPDF + md-editor
|
||||
|
||||
Reference in New Issue
Block a user