# Multi-stage build for Next.js 16 with Webpack (not Turbopack) # Using Debian Slim for better Prisma compatibility FROM node:22-slim AS base # Install dependencies only when needed FROM base AS deps WORKDIR /app # Install system dependencies for Prisma and sharp RUN apt-get update && apt-get install -y --no-install-recommends \ openssl \ && rm -rf /var/lib/apt/lists/* # Install dependencies based on the preferred package manager COPY package.json package-lock.json* ./ RUN npm install --legacy-peer-deps # Rebuild the source code only when needed FROM base AS builder WORKDIR /app COPY --from=deps /app/node_modules ./node_modules COPY . . # Generate Prisma Client before build RUN npx prisma generate # Build Next.js with Webpack (not Turbopack) to avoid Tailwind CSS issues ENV NEXT_TELEMETRY_DISABLED=1 RUN npm run build # Ensure Prisma binaries are in all search locations RUN mkdir -p /app/prisma/client-generated && \ cp -r node_modules/.prisma/client/* /app/prisma/client-generated/ && \ mkdir -p /app/.prisma/client && \ cp -r node_modules/.prisma/client/* /app/.prisma/client/ && \ mkdir -p /app/.next/server && \ cp -r node_modules/@prisma/engines/*.node /app/.next/server/ 2>/dev/null || true # Production image, copy all the files and run next FROM base AS runner WORKDIR /app ENV NODE_ENV=production ENV NEXT_TELEMETRY_DISABLED=1 RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nextjs COPY --from=builder /app/public ./public # Set the correct permission for prerender cache RUN mkdir .next RUN chown nextjs:nodejs .next # Automatically leverage output traces to reduce image size COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static COPY --from=builder --chown=nextjs:nodejs /app/.next/server ./.next/server # Copy Prisma for runtime - ALL locations including the generated client AND engines COPY --from=builder /app/prisma ./prisma COPY --from=builder /app/.prisma ./.prisma COPY --from=builder --chown=nextjs:nodejs /app/node_modules/.prisma ./node_modules/.prisma COPY --from=builder --chown=nextjs:nodejs /app/node_modules/@prisma ./node_modules/@prisma USER nextjs EXPOSE 3000 ENV PORT=3000 ENV HOSTNAME="0.0.0.0" # server.js is created by next build from the standalone output CMD ["node", "server.js"]