-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile.prod
More file actions
65 lines (50 loc) · 1.85 KB
/
Dockerfile.prod
File metadata and controls
65 lines (50 loc) · 1.85 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
# Stage 1: Pruning
FROM node:20-slim AS pruner
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
WORKDIR /app
COPY . .
# Use turbo to create a pruned version of the workspace focusing on web and core
RUN pnpm dlx turbo prune @borg/web @borg/core --docker
# Stage 2: Builder
FROM node:20-slim AS builder
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
WORKDIR /app
# First install dependencies (as they change less often)
COPY --from=pruner /app/out/json/ .
COPY --from=pruner /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
RUN pnpm install --frozen-lockfile
# Copy source code and build
COPY --from=pruner /app/out/full/ .
RUN pnpm run build
# Stage 3: Core Production Runner
FROM node:20-slim AS core-runner
ENV NODE_ENV=production
WORKDIR /app
# Copy built outputs and dependencies
COPY --from=builder /app/packages/core/package.json ./packages/core/
COPY --from=builder /app/packages/core/dist ./packages/core/dist
COPY --from=builder /app/node_modules ./node_modules
EXPOSE 3000
# Healthcheck
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
CMD node -e "require('http').request('http://localhost:3000/api/health').end()" || exit 1
CMD ["node", "packages/core/dist/index.js"]
# Stage 4: Web Production Runner (Next.js Standalone)
FROM node:20-slim AS web-runner
ENV NODE_ENV=production
WORKDIR /app
# Next.js standalone output contains node_modules and all necessary files
COPY --from=builder /app/apps/web/.next/standalone ./
COPY --from=builder /app/apps/web/.next/static ./apps/web/.next/static
COPY --from=builder /app/apps/web/public ./apps/web/public
EXPOSE 8080
ENV PORT=8080
ENV HOSTNAME="0.0.0.0"
# Healthcheck
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
CMD node -e "require('http').request('http://localhost:8080/api/health').end()" || exit 1
CMD ["node", "apps/web/server.js"]