From 3548eabf68a9a3f69383d279420e198b2f93ea9f Mon Sep 17 00:00:00 2001 From: corenthin-lebreton Date: Thu, 26 Feb 2026 22:17:14 +0100 Subject: [PATCH] Dockerfile modif2 --- .dockerignore | 27 ++++++++++++++------------- Dockerfile | 23 +++++++++++++---------- docker-compose.yml | 26 ++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 23 deletions(-) create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore index 1f1719f..0c537a0 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,14 +1,14 @@ -# Dépendances — réinstallées dans le conteneur +# ─── Dépendances ─────────────────────────────────────────── node_modules .pnp .pnp.js -# Artefacts de build +# ─── Artefacts de build ──────────────────────────────────── .next out dist -# Outils de dev +# ─── Outils de développement ─────────────────────────────── .git .gitignore .github @@ -18,30 +18,31 @@ npm-debug.log* yarn-debug.log* yarn-error.log* -# Secrets locaux — jamais dans l'image +# ─── Secrets locaux — jamais dans l'image ────────────────── +# Les valeurs NEXT_PUBLIC_* passent via --build-arg / docker-compose +# Les secrets (SERVICE_ROLE_KEY) sont injectés au runtime via --env-file .env .env.* -!.env.example !.env.local.example -# Tests / CI +# ─── Tests / CI ──────────────────────────────────────────── coverage .nyc_output __tests__ *.test.ts *.spec.ts -# Docs +# ─── Documentation ───────────────────────────────────────── *.md -!README.md -# Docker -Dockerfile -.dockerignore +# ─── Docker ──────────────────────────────────────────────── +docker-compose.yml +docker-compose*.yml -# Supabase +# ─── Supabase (migrations locales) ───────────────────────── supabase/ -# Divers +# ─── Divers ──────────────────────────────────────────────── .DS_Store Thumbs.db +quiz-example.json diff --git a/Dockerfile b/Dockerfile index 326cce7..be9f4e4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,6 @@ WORKDIR /app COPY package.json package-lock.json* ./ -# ci : installation déterministe depuis le lock-file RUN npm ci @@ -25,15 +24,19 @@ WORKDIR /app COPY --from=deps /app/node_modules ./node_modules COPY . . -# Variables publiques (NEXT_PUBLIC_*) nécessaires au build. -# Les secrets serveur (SERVICE_ROLE_KEY…) ne sont JAMAIS passés ici. -ARG NEXT_PUBLIC_SUPABASE_URL -ARG NEXT_PUBLIC_SUPABASE_ANON_KEY +# Variables publiques nécessaires à la compilation du bundle client. +# Passer via --build-arg ou docker-compose (voir docker-compose.yml). +# Les valeurs vides sont acceptées : les pages sont dynamiques (cookies), +# donc aucune pré-rendu statique ne les utilise au build. +ARG NEXT_PUBLIC_SUPABASE_URL="" +ARG NEXT_PUBLIC_SUPABASE_ANON_KEY="" ENV NEXT_PUBLIC_SUPABASE_URL=$NEXT_PUBLIC_SUPABASE_URL \ NEXT_PUBLIC_SUPABASE_ANON_KEY=$NEXT_PUBLIC_SUPABASE_ANON_KEY \ NEXT_TELEMETRY_DISABLED=1 \ - NODE_ENV=production + NODE_ENV=production \ + # Allouer suffisamment de mémoire pour le build Next.js + NODE_OPTIONS="--max-old-space-size=4096" RUN npm run build @@ -54,7 +57,7 @@ RUN addgroup --system --gid 1001 nodejs && \ # Fichiers publics (favicon, images statiques…) COPY --from=builder /app/public ./public -# Serveur Next.js standalone (bundle minimal sans node_modules complets) +# Serveur Next.js standalone (bundle minimal, sans node_modules complets) COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ # Assets statiques compilés (_next/static) @@ -67,10 +70,10 @@ ENV NODE_ENV=production \ PORT=3000 \ HOSTNAME="0.0.0.0" -# Les secrets injectés au runtime (jamais dans l'image) : +# Secrets injectés au runtime uniquement (jamais baked dans l'image) : +# NEXT_PUBLIC_SUPABASE_URL +# NEXT_PUBLIC_SUPABASE_ANON_KEY # SUPABASE_SERVICE_ROLE_KEY -# NEXT_PUBLIC_SUPABASE_URL (si non baked au build) -# NEXT_PUBLIC_SUPABASE_ANON_KEY (si non baked au build) EXPOSE 3000 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..ff8532b --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,26 @@ +services: + solyquiz: + build: + context: . + dockerfile: Dockerfile + # Les variables NEXT_PUBLIC_* sont lues depuis le fichier .env + # grâce à env_file, puis transmises comme build args + args: + NEXT_PUBLIC_SUPABASE_URL: ${NEXT_PUBLIC_SUPABASE_URL} + NEXT_PUBLIC_SUPABASE_ANON_KEY: ${NEXT_PUBLIC_SUPABASE_ANON_KEY} + image: solyquiz:latest + container_name: solyquiz + ports: + - "3000:3000" + # Secrets injectés uniquement au runtime (non présents dans l'image) + env_file: + - .env + environment: + NODE_ENV: production + restart: unless-stopped + # Limite les ressources pour éviter les abus + deploy: + resources: + limits: + memory: 512m + cpus: "1.0"