1+ # ============
2+ # Base stage
3+ # ============
4+ FROM node:20-bullseye-slim AS base
5+ # Use the official Node 20 image based on bullseye slim.
6+ # This stage serves as the base image for all subsequent stages.
7+
8+ # ============
9+ # Builder stage
10+ # ============
11+ FROM base AS builder
12+
13+ WORKDIR /app
14+
15+ # Install Turbo globally as it is needed during the build.
16+ RUN npm install -g
[email protected] 17+
18+ # Copy all application source code.
19+ COPY . .
20+
21+ # Prune the workspace to only include the necessary scopes.
22+ RUN turbo prune --docker --scope @agent-reactflow/backend
23+
24+ # ============
25+ # Installer stage
26+ # ============
27+ FROM base AS installer
28+
29+ WORKDIR /app
30+
31+ # Update the certificate store in this Debian-based stage.
32+ RUN apt-get update && \
33+ apt-get install -y ca-certificates && \
34+ update-ca-certificates
35+
36+ RUN npm install -g
[email protected] && \
37+ 38+
39+ # Copy pre-pruned dependency files from the builder stage.
40+ COPY --from=builder /app/out/json/ .
41+ COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
42+
43+ # Install dependencies.
44+ RUN pnpm install
45+
46+ # Copy the full application and build it.
47+ COPY --from=builder /app/out/full/ .
48+ RUN pnpm build
49+
50+ # ============
51+ # Final Runner stage
52+ # ============
53+ FROM node:20-alpine AS runner
54+
55+ WORKDIR /app
56+
57+ # Copy the production-ready built application from the installer stage.
58+ COPY --from=installer /app .
59+
60+ # Install only runtime packages. Here we install curl and ca-certificates,
61+ # then update the certificate store for secure TLS connections.
62+ RUN npm install -g
[email protected] && \
63+ apk add --no-cache curl ca-certificates && update-ca-certificates
64+
65+ # Start the application using pnpm.
66+ CMD ["pnpm" , "start" ]
67+
68+ # # Dummy shell for troubleshooting
69+ # CMD ["sh"]
0 commit comments