From b54744a6d87059d8f3ee6848e845ae12694bd36c Mon Sep 17 00:00:00 2001 From: Puechberty Arthur Date: Tue, 31 Mar 2026 19:26:44 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20configurer=20Docker=20pour=20le=20build?= =?UTF-8?q?=20et=20l'ex=C3=A9cution=20de=20l'application=20Next.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 34 ++++++++++++++++++++++++++++++++++ docker-compose.yml | 13 +++++++------ next.config.ts | 9 ++++++++- 3 files changed, 49 insertions(+), 7 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..193b26c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,34 @@ +# === Étape 1 : Build === +FROM node:20-alpine AS builder + +WORKDIR /app + +# Copier les fichiers de dépendances pour profiter du cache Docker +COPY package*.json ./ + +# Installer uniquement ce qu'il faut pour le build +RUN npm ci + +# Copier tout le code +COPY . . + +# Build Next.js pour la production +RUN npm run build + +# === Étape 2 : Runner léger === +FROM node:20-alpine AS runner + +WORKDIR /app + +# Copier uniquement ce qui est nécessaire pour la prod +COPY --from=builder /app/package*.json ./ +COPY --from=builder /app/node_modules ./node_modules +COPY --from=builder /app/.next ./.next +COPY --from=builder /app/public ./public + +# Mode production +ENV NODE_ENV=production +EXPOSE 3000 + +# Lancer le serveur Next.js +CMD ["npm", "start"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index c042f06..a47d63b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,10 +1,11 @@ services: web: - image: node:20-alpine - working_dir: /app + build: . + ports: + - "3000:3000" volumes: - ./:/app - ports: - - "3004:3000" - command: sh -c "npm install && npm run build && npm start" - restart: unless-stopped \ No newline at end of file + - /app/node_modules + environment: + - NODE_ENV=development + command: npm run dev \ No newline at end of file diff --git a/next.config.ts b/next.config.ts index e9ffa30..6007e2e 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,7 +1,14 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { - /* config options here */ + // Mode production strict pour React (détecte les erreurs tôt) + reactStrictMode: true, + + // Build standalone pour Docker → image finale légère et indépendante + output: "standalone", + + // Compression des pages côté serveur (gzip/brotli) + compress: true, }; export default nextConfig;