From 8ec4300b92042d9c5fba0b79657a3f3ab891058e Mon Sep 17 00:00:00 2001 From: Debian Dev4 Date: Tue, 23 Sep 2025 23:54:56 +0000 Subject: [PATCH] ci: docker_tag=ext - Fix CI build with multi-stage Dockerfile - Add multi-stage Dockerfile with 'ext' stage for CI compatibility - Fix start-runtime.js to use 'npm start' instead of 'node server.js' - Ensure image can be built with target stage 'ext' as expected by CI - Maintain runtime environment variable injection capability --- Dockerfile | 26 ++++++++++++++++++++------ start-runtime.js | 2 +- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 89a7aeb8..f94a1ab3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,7 @@ -# Dockerfile optimisé pour la CI - build générique, variables au runtime -FROM docker.io/library/debian:bookworm-slim +# Dockerfile multi-stage pour la CI - build générique, variables au runtime + +# Stage de base +FROM docker.io/library/debian:bookworm-slim AS base # Installation des dépendances système RUN apt-get update && apt-get upgrade -y && \ @@ -16,6 +18,9 @@ RUN curl -fsSL https://deb.nodesource.com/setup_19.x | bash - && \ WORKDIR /leCoffre-front +# Stage de build +FROM base AS builder + # Copie des fichiers de dépendances COPY package.json package-lock.json ./ RUN npm install --no-audit --no-fund @@ -47,15 +52,24 @@ ENV NEXT_PUBLIC_BACK_API_PROTOCOL=https \ RUN npm run build +# Stage de production (stage 'ext' pour la CI) +FROM base AS ext + +# Copie des fichiers buildés depuis le stage builder +COPY --from=builder /leCoffre-front/.next ./.next +COPY --from=builder /leCoffre-front/public ./public +COPY --from=builder /leCoffre-front/package.json ./package.json +COPY --from=builder /leCoffre-front/node_modules ./node_modules + +# Copie du script de démarrage +COPY start-runtime.js ./ +RUN chmod +x start-runtime.js + # Configuration runtime EXPOSE 8080 ENV NODE_ENV=production ENV PORT=8080 -# Copie du script de démarrage et permissions -COPY start-runtime.js ./ -RUN chmod +x start-runtime.js - # Utilisateur non-root RUN useradd -m -u 1000 lecoffreuser && \ mkdir -p /leCoffre-front && chown -R lecoffreuser:lecoffreuser /leCoffre-front diff --git a/start-runtime.js b/start-runtime.js index ab1a603d..7dcc7e1c 100644 --- a/start-runtime.js +++ b/start-runtime.js @@ -34,7 +34,7 @@ const env = { ...defaultEnv, ...process.env }; console.log('Starting Next.js with runtime environment variables...'); // Démarrer Next.js avec les variables injectées -const nextProcess = spawn('node', ['server.js'], { +const nextProcess = spawn('npm', ['start'], { env: env, stdio: 'inherit', cwd: __dirname