-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
78 lines (53 loc) · 2.42 KB
/
Dockerfile
File metadata and controls
78 lines (53 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
FROM node:22-alpine AS base
# Install pnpm
RUN corepack enable && corepack prepare pnpm@latest --activate
FROM base AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json pnpm-lock.yaml .npmrc* ./
RUN pnpm config set node-linker hoisted && pnpm install --frozen-lockfile
FROM base AS prod-deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json pnpm-lock.yaml .npmrc* ./
# --ignore-scripts: skip lifecycle scripts (avoids "husky: not found" from prepare)
RUN pnpm config set node-linker hoisted && pnpm install --frozen-lockfile --prod --ignore-scripts
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Generate Prisma client before building
RUN pnpm db:generate
RUN pnpm run build
FROM base AS runner
WORKDIR /app
ENV NODE_ENV=production
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Production node_modules (includes socket.io, ioredis, tsx, etc.)
COPY --from=prod-deps --chown=nextjs:nodejs /app/node_modules ./node_modules
# Prisma engine binaries (postinstall was skipped by --ignore-scripts in prod-deps)
# In Prisma 6.x the engine is included in the generated output (src/generated/prisma/)
# which is copied below via the src/ COPY. We only need @prisma/engines from builder.
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/@prisma/engines ./node_modules/@prisma/engines
# package.json (needed by tsx / module resolution)
COPY --from=builder --chown=nextjs:nodejs /app/package.json ./
# Next.js build output
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
# Next.js & TypeScript config (needed at runtime by the custom server)
COPY --from=builder --chown=nextjs:nodejs /app/next.config.ts ./
COPY --from=builder --chown=nextjs:nodejs /app/tsconfig.json ./
# Source files needed for the custom server (tsx transpiles at runtime)
COPY --from=builder --chown=nextjs:nodejs /app/src ./src
# Prisma schema & config (needed by prisma migrate deploy)
COPY --from=builder --chown=nextjs:nodejs /app/prisma ./prisma
COPY --from=builder --chown=nextjs:nodejs /app/prisma.config.ts ./
# Whitelist files (needed by auth logic)
COPY --from=builder --chown=nextjs:nodejs /app/admin_whitelist.txt ./
COPY --from=builder --chown=nextjs:nodejs /app/whitelist.txt ./
USER nextjs
EXPOSE 3000
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
CMD ["npx", "tsx", "src/server.ts"]