From 09ebb795cd5d26246fe4a16a058292c19c49865f Mon Sep 17 00:00:00 2001 From: Silvio Date: Sun, 31 May 2026 17:41:23 -0500 Subject: [PATCH] =?UTF-8?q?fix:=20Dockerfile=20server.js=20discovery=20?= =?UTF-8?q?=E2=80=94=20handle=20flat=20and=20nested=20standalone=20output?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Removed fragile find/cp flatten logic in builder - Runner now copies full standalone/ and symlinks server.js if nested - Fixes MODULE_NOT_FOUND when Next.js creates flat vs nested output - Port 3020 and APP_DIR /home/ubuntu/cirux confirmed consistent --- Dockerfile | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9255c4b..4f90415 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,13 @@ -# ─── Stage 1: Builder (install ALL deps + build) ──────────────────────────── +# ─── Stage 1: Builder ─────────────────────────────────────────────────────── FROM node:20-alpine AS builder RUN apk add --no-cache libc6-compat WORKDIR /app -# Copy dependency files first (cache layer) COPY package.json package-lock.json ./ RUN npm ci && npm cache clean --force -# Copy source code COPY . . -# Build requires these env vars for static analysis ARG NEXT_PUBLIC_SUPABASE_URL ARG NEXT_PUBLIC_SUPABASE_ANON_KEY ENV NEXT_PUBLIC_SUPABASE_URL=$NEXT_PUBLIC_SUPABASE_URL @@ -18,17 +15,6 @@ ENV NEXT_PUBLIC_SUPABASE_ANON_KEY=$NEXT_PUBLIC_SUPABASE_ANON_KEY RUN npm run build -# Flatten standalone output — find the single subdir Next.js creates -RUN set -e && \ - echo "=== Standalone output ===" && \ - ls -la /app/.next/standalone/ && \ - mkdir -p /app/.next/standalone-export && \ - STANDALONE_DIR=$(find /app/.next/standalone -maxdepth 1 -mindepth 1 -type d | head -1) && \ - echo "Copying from: $STANDALONE_DIR" && \ - cp -r "$STANDALONE_DIR"/* /app/.next/standalone-export/ && \ - ls -la /app/.next/standalone-export/ && \ - test -f /app/.next/standalone-export/server.js && echo "✅ server.js found" || (echo "❌ server.js NOT FOUND" && exit 1) - # ─── Stage 2: Production Runner ──────────────────────────────────────────── FROM node:20-alpine AS runner WORKDIR /app @@ -37,12 +23,22 @@ ENV NODE_ENV=production ENV PORT=3020 ENV HOSTNAME=0.0.0.0 -# Create non-root user -RUN addgroup --system --gid 1001 nodejs -RUN adduser --system --uid 1001 nextjs +RUN addgroup --system --gid 1001 nodejs && \ + adduser --system --uid 1001 nextjs -# Copy flattened standalone output (server.js directly in /app) -COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone-export/ ./ +# Copy full standalone output (may be flat or contain a subdir) +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ + +# Ensure server.js exists at /app/server.js (create symlink if nested) +RUN if [ ! -f /app/server.js ]; then \ + SERVER_PATH=$(find /app -maxdepth 2 -name server.js | head -1) && \ + if [ -n "$SERVER_PATH" ]; then \ + ln -s "$SERVER_PATH" /app/server.js && \ + echo "Symlinked server.js: $SERVER_PATH -> /app/server.js"; \ + else \ + echo "ERROR: server.js not found" && exit 1; \ + fi; \ + fi # Copy static assets COPY --from=builder --chown=nextjs:nodejs /app/public ./public