-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
112 lines (77 loc) · 4.08 KB
/
Dockerfile
File metadata and controls
112 lines (77 loc) · 4.08 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# ── Stage 1: Install dependencies ─────────────────────────────────────────────
FROM node:20-alpine AS deps
RUN apk add --no-cache libc6-compat
RUN corepack enable && corepack prepare pnpm@9 --activate
WORKDIR /app
COPY package.json pnpm-lock.yaml .npmrc ./
RUN pnpm install --no-frozen-lockfile
# ── Stage 2: Build the application ───────────────────────────────────────────
FROM node:20-alpine AS builder
RUN corepack enable && corepack prepare pnpm@9 --activate
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
ENV NEXT_TELEMETRY_DISABLED=1
ENV NODE_ENV=production
# Cache bust: change this value to force Docker to re-run pnpm build
ARG CACHE_BUST=3
RUN pnpm build
# ── Stage 3: Database migration runner ───────────────────────────────────────
# Runs `prisma migrate deploy` once at startup, then exits (restart: no).
FROM node:20-alpine AS migrate
RUN corepack enable && corepack prepare pnpm@9 --activate
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY prisma ./prisma
COPY package.json pnpm-lock.yaml .npmrc ./
ENV NODE_ENV=production
CMD ["npx", "prisma", "migrate", "deploy"]
# ── Stage 4: BullMQ worker ────────────────────────────────────────────────────
# Processes flow.execute, eval.run, and webhook.retry jobs from Redis queue.
# Requires REDIS_URL and DATABASE_URL environment variables.
FROM node:20-alpine AS worker
RUN corepack enable && corepack prepare pnpm@9 --activate
WORKDIR /app
# Use the full deps (includes devDeps for tsx TypeScript execution)
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Regenerate Prisma client for the correct binary target
RUN pnpm db:generate
ENV NODE_ENV=production
HEALTHCHECK --interval=30s --timeout=10s --start-period=20s --retries=3 \
CMD node -e "require('http').get('http://localhost:${PORT:-8080}/health', r => process.exit(r.statusCode === 200 ? 0 : 1)).on('error', () => process.exit(1))"
CMD ["npx", "tsx", "src/lib/queue/worker.ts"]
# ── Stage 5: Production runner (LAST — Railway builds this stage) ─────────────
FROM node:20-alpine AS runner
# Install LSP server binaries for the lsp_query node (Phase F1)
# typescript-language-server handles TypeScript + JavaScript
# pyright-langserver (via pyright) handles Python
# vitest is installed globally because Next.js standalone output prunes node_modules
# by tracing imports — vitest is only a CLI tool, never imported, so it is absent
# from /app/node_modules in production. Global install puts it at /usr/local/bin/vitest.
RUN apk add --no-cache curl python3 git && \
npm install -g typescript typescript-language-server pyright vitest --no-fund --no-audit
WORKDIR /app
ENV NEXT_TELEMETRY_DISABLED=1
ENV NODE_ENV=production
ENV PORT=3000
ENV HOSTNAME=0.0.0.0
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
COPY --from=builder /app/public ./public
RUN mkdir .next
RUN chown nextjs:nodejs .next
# Copy Next.js standalone output — server.js lands at /app/server.js
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
# Prisma engine binaries are bundled in standalone output
COPY --from=builder --chown=nextjs:nodejs /app/prisma ./prisma
COPY --from=builder --chown=nextjs:nodejs /app/src/generated ./src/generated
# tiktoken WASM binary (not traced by Next.js standalone)
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/tiktoken ./node_modules/tiktoken
USER nextjs
EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD curl -f http://localhost:3000/api/health || exit 1
# server.js is at /app/server.js after COPY --from=builder /app/.next/standalone ./
CMD ["node", "server.js"]