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:
+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"]
|
||||
Reference in New Issue
Block a user