From 6ba046272d20c76fd8cae2bea960464b059423f2 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 15 Aug 2025 07:11:17 +0000 Subject: [PATCH] feat: Optimize Docker image with standalone output This commit optimizes the Docker image size by leveraging Next.js's standalone output feature. Key changes: - Enabled `output: 'standalone'` in `frontend/next.config.mjs`. - Modified the `Dockerfile` to build a smaller production image: - Copies only the necessary artifacts from the frontend build (`.next/standalone`, `.next/static`, `public`). - Removes the need to copy the entire `node_modules` directory. - Updates the startup script to use `node server.js` to run the frontend server. This significantly reduces the final image size, addressing the user's request for a smaller Docker image. --- Dockerfile | 12 ++++++------ frontend/next.config.mjs | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 371fa0e..0a9fd74 100644 --- a/Dockerfile +++ b/Dockerfile @@ -54,10 +54,9 @@ COPY --from=backend-builder /app/.venv /app/.venv COPY backend/*.py ./ # Copy built frontend from previous stage -COPY --from=frontend-builder /app/frontend/.next ./.next -COPY --from=frontend-builder /app/frontend/public ./public -COPY --from=frontend-builder /app/frontend/package.json ./package.json -COPY --from=frontend-builder /app/frontend/node_modules ./node_modules +COPY --from=frontend-builder /app/frontend/.next/standalone /app/ +COPY --from=frontend-builder /app/frontend/public /app/public +COPY --from=frontend-builder /app/frontend/.next/static /app/.next/static # Expose ports EXPOSE 8000 3000 @@ -68,13 +67,14 @@ ENV PYTHONPATH=/app \ UVICORN_PORT=8000 \ PATH="/app/.venv/bin:$PATH" \ VIRTUAL_ENV=/app/.venv \ - NODE_ENV=production + NODE_ENV=production \ + PORT=3000 # Create startup script for better process management RUN echo '#!/bin/bash\n\ uv run uvicorn main:app --host $UVICORN_HOST --port $UVICORN_PORT &\n\ BACKEND_PID=$!\n\ - cd /app && PORT=3000 npx next start &\n\ + node /app/server.js &\n\ FRONTEND_PID=$!\n\ wait $BACKEND_PID $FRONTEND_PID' > /app/start.sh && chmod +x /app/start.sh diff --git a/frontend/next.config.mjs b/frontend/next.config.mjs index e6c8996..133e5b2 100644 --- a/frontend/next.config.mjs +++ b/frontend/next.config.mjs @@ -4,6 +4,7 @@ const withNextIntl = createNextIntlPlugin('./i18n.ts'); /** @type {import('next').NextConfig} */ const nextConfig = { + output: 'standalone', compiler: { removeConsole: process.env.NODE_ENV === "production"