Files
cirux/Dockerfile
T
silvioalzate 09ebb795cd fix: Dockerfile server.js discovery — handle flat and nested standalone output
- 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
2026-05-31 17:41:23 -05:00

55 lines
1.9 KiB
Docker

# ─── Stage 1: Builder ───────────────────────────────────────────────────────
FROM node:20-alpine AS builder
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci && npm cache clean --force
COPY . .
ARG NEXT_PUBLIC_SUPABASE_URL
ARG NEXT_PUBLIC_SUPABASE_ANON_KEY
ENV NEXT_PUBLIC_SUPABASE_URL=$NEXT_PUBLIC_SUPABASE_URL
ENV NEXT_PUBLIC_SUPABASE_ANON_KEY=$NEXT_PUBLIC_SUPABASE_ANON_KEY
RUN npm run build
# ─── Stage 2: Production Runner ────────────────────────────────────────────
FROM node:20-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV PORT=3020
ENV HOSTNAME=0.0.0.0
RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 nextjs
# 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
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
USER nextjs
EXPOSE 3020
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD node -e "require('http').get('http://localhost:3020/api/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})" || exit 1
CMD ["node", "server.js"]