Dockerfile 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. FROM node:22-alpine AS base
  2. RUN apk add --no-cache libc6-compat openssl postgresql-client bash ffmpeg
  3. # Install dependencies only when needed
  4. FROM base AS deps
  5. WORKDIR /app
  6. COPY package.json package-lock.json* ./
  7. COPY prisma ./prisma/
  8. COPY prisma.config.ts ./prisma.config.ts
  9. RUN npm ci
  10. # Rebuild the source code only when needed
  11. FROM base AS builder
  12. WORKDIR /app
  13. COPY --from=deps /app/node_modules ./node_modules
  14. COPY . .
  15. # Generate Prisma client
  16. RUN npx prisma generate
  17. ENV NEXT_TELEMETRY_DISABLED=1
  18. RUN npm run build
  19. # Production image, copy all the files and run next
  20. FROM base AS runner
  21. WORKDIR /app
  22. ARG APP_VERSION=development
  23. ENV APP_VERSION=${APP_VERSION}
  24. ENV NODE_ENV=production
  25. ENV NEXT_TELEMETRY_DISABLED=1
  26. RUN addgroup --system --gid 1001 nodejs && \
  27. adduser --system --uid 1001 --home /home/nextjs nextjs
  28. # Copy public assets
  29. COPY --from=builder /app/public ./public
  30. # Set correct permissions for prerender cache
  31. RUN mkdir .next && chown nextjs:nodejs .next
  32. # Copy standalone build
  33. COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
  34. COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
  35. # Copy prisma schema and config for migrations
  36. COPY --from=builder --chown=nextjs:nodejs /app/prisma ./prisma
  37. COPY --from=builder --chown=nextjs:nodejs /app/prisma.config.ts ./prisma.config.ts
  38. # Copy generated Prisma client
  39. COPY --from=builder --chown=nextjs:nodejs /app/src/generated ./src/generated
  40. # Remove Next.js standalone's traced stubs for pg/prisma (tracer copies package.json
  41. # but not all files), then install the full runtime packages fresh.
  42. RUN rm -rf \
  43. /app/node_modules/pg \
  44. /app/node_modules/pg-types \
  45. /app/node_modules/pg-pool \
  46. /app/node_modules/pg-connection-string \
  47. /app/node_modules/pg-protocol \
  48. /app/node_modules/pg-int8 \
  49. /app/node_modules/pg-cloudflare \
  50. /app/node_modules/pgpass \
  51. /app/node_modules/postgres-array \
  52. /app/node_modules/postgres-bytea \
  53. /app/node_modules/postgres-date \
  54. /app/node_modules/postgres-interval \
  55. /app/node_modules/split2 \
  56. /app/node_modules/prisma \
  57. /app/node_modules/@prisma \
  58. /app/node_modules/.prisma \
  59. && npm install prisma@7.6.0 @prisma/client@7.6.0 @prisma/adapter-pg@7.6.0 pg dotenv tsx
  60. # The npm install above re-resolves the dependency tree and replaces the
  61. # standalone build's PATCHED next package with a fresh unpatched copy from the
  62. # registry, which silently breaks all WebSocket routes (live updates, work
  63. # board sync). Re-apply the next-ws patch so the runtime server can accept
  64. # WebSocket upgrades. next-ws itself is already in the standalone bundle.
  65. RUN npx next-ws patch --yes
  66. # Copy init script
  67. COPY --chown=nextjs:nodejs init-db.sh ./init-db.sh
  68. RUN chmod +x ./init-db.sh
  69. # Create uploads directories
  70. RUN mkdir -p /app/data/uploads && chown -R nextjs:nodejs /app/data
  71. USER nextjs
  72. EXPOSE 3000
  73. ENV PORT=3000
  74. ENV HOSTNAME="0.0.0.0"
  75. ENTRYPOINT ["./init-db.sh"]
  76. CMD ["node", "server.js"]