forked from quantified-uncertainty/roast-my-post
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
78 lines (58 loc) · 2.69 KB
/
Copy pathDockerfile
File metadata and controls
78 lines (58 loc) · 2.69 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
# Build stage
FROM node:22-alpine AS builder
WORKDIR /usr/src/app
# Install dependencies for native modules and enable corepack
RUN apk add --no-cache libc6-compat python3 make g++
RUN corepack enable && corepack prepare pnpm@latest --activate
# Copy all source files
COPY . .
# Install all dependencies with cache mount
RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
pnpm install --frozen-lockfile
# Generate Prisma client with correct binary target for Alpine Linux
RUN cd internal-packages/db && \
npx prisma generate --schema=./prisma/schema.prisma && \
cd ../..
# Build workspace packages that need dist files (in dependency order)
RUN pnpm --filter @roast/db run build && \
pnpm --filter @roast/domain run build && \
pnpm --filter @roast/ai run build && \
pnpm --filter @roast/jobs run build
# Build web app with dummy env vars for validation only
RUN NEXT_TELEMETRY_DISABLED=1 \
DOCKER_BUILD=true \
DATABASE_URL="postgresql://dummy:dummy@localhost:5432/dummy?schema=public" \
AUTH_SECRET="build-time-dummy" \
ANTHROPIC_API_KEY="build-time-dummy" \
pnpm --filter @roast/web run build
# Deploy web app with dependencies
RUN pnpm deploy --filter=@roast/web --prod /prod/web
# Copy the built Next.js app (.next directory) that pnpm deploy doesn't include
RUN cp -r /usr/src/app/apps/web/.next /prod/web/.next
# Ensure Prisma generated files are included (pnpm deploy might miss them)
RUN mkdir -p /prod/web/node_modules/@roast/db/generated && \
cp -r /usr/src/app/internal-packages/db/generated/* /prod/web/node_modules/@roast/db/generated/ || true
# Production stage
FROM node:22-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
# Install runtime dependencies and enable corepack
RUN apk add --no-cache libc6-compat
RUN corepack enable && corepack prepare pnpm@latest --activate
# Create non-root user
RUN addgroup -g 1001 -S nodejs && \
adduser -S nextjs -u 1001
# Copy deployed web app (includes built app and pruned dependencies)
COPY --from=builder --chown=nextjs:nodejs /prod/web ./
# Set exact path to Prisma query engine to avoid wildcard resolution issues
ENV PRISMA_QUERY_ENGINE_LIBRARY=/app/node_modules/@roast/db/generated/libquery_engine-linux-musl-openssl-3.0.x.so.node
# Ensure Prisma binary is available and executable
RUN chmod +x node_modules/@roast/db/generated/libquery_engine-linux-musl-openssl-3.0.x.so.node || true
USER nextjs
EXPOSE 3000
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD node -e "require('http').get('http://localhost:3000/api/health', (res) => res.statusCode === 200 ? process.exit(0) : process.exit(1))"
# Start the application
CMD ["pnpm", "start"]