Dockerfile 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. # Copy init script
  61. COPY --chown=nextjs:nodejs init-db.sh ./init-db.sh
  62. RUN chmod +x ./init-db.sh
  63. # Create uploads directories
  64. RUN mkdir -p /app/data/uploads && chown -R nextjs:nodejs /app/data
  65. USER nextjs
  66. EXPOSE 3000
  67. ENV PORT=3000
  68. ENV HOSTNAME="0.0.0.0"
  69. ENTRYPOINT ["./init-db.sh"]
  70. CMD ["node", "server.js"]