Skip to content

Commit dc20229

Browse files
waleedlatif1claude
andauthored
perf(docker): use turbo prune for app.Dockerfile (#4322)
* perf(docker): refactor app.Dockerfile to use turbo prune Replaces manual workspace package.json copies with `turbo prune sim --docker`, matching the canonical Vercel/Turborepo monorepo pattern (and the existing realtime.Dockerfile). - New `pruner` stage emits `out/json` (manifests + lockfile) and `out/full` (sources) for only the packages sim actually depends on. - `deps` stage installs from the pruned manifest, so cache invalidates only when package.json/bun.lock change — not on source edits. - Drops 24 lines of brittle manual COPYs (one per workspace package). - Single full install in deps (no --omit=dev) so build-time devDeps like tailwindcss/postcss are available — replaces the earlier hotfix that did a second install in the builder stage. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * chore(docker): pin turbo to 2.9.6 in pruner stage Match the version locked in package.json so pruner output is reproducible across builds. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 69dc2f0 commit dc20229

1 file changed

Lines changed: 24 additions & 59 deletions

File tree

docker/app.Dockerfile

Lines changed: 24 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,35 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
1111
&& curl -fsSL https://deb.nodesource.com/setup_22.x | bash - \
1212
&& apt-get install -y nodejs
1313

14+
# ========================================
15+
# Pruner Stage: Emit a minimal monorepo subset that sim depends on
16+
# ========================================
17+
FROM base AS pruner
18+
WORKDIR /app
19+
20+
RUN bun install -g turbo@2.9.6
21+
22+
COPY . .
23+
24+
RUN turbo prune sim --docker
25+
1426
# ========================================
1527
# Dependencies Stage: Install Dependencies
1628
# ========================================
1729
FROM base AS deps
1830
WORKDIR /app
1931

20-
COPY package.json bun.lock turbo.json ./
21-
RUN mkdir -p apps \
22-
packages/audit \
23-
packages/db \
24-
packages/logger \
25-
packages/realtime-protocol \
26-
packages/security \
27-
packages/testing \
28-
packages/tsconfig \
29-
packages/utils \
30-
packages/workflow-authz \
31-
packages/workflow-persistence \
32-
packages/workflow-types
33-
COPY apps/sim/package.json ./apps/sim/package.json
34-
COPY packages/audit/package.json ./packages/audit/package.json
35-
COPY packages/db/package.json ./packages/db/package.json
36-
COPY packages/logger/package.json ./packages/logger/package.json
37-
COPY packages/realtime-protocol/package.json ./packages/realtime-protocol/package.json
38-
COPY packages/security/package.json ./packages/security/package.json
39-
COPY packages/testing/package.json ./packages/testing/package.json
40-
COPY packages/tsconfig/package.json ./packages/tsconfig/package.json
41-
COPY packages/utils/package.json ./packages/utils/package.json
42-
COPY packages/workflow-authz/package.json ./packages/workflow-authz/package.json
43-
COPY packages/workflow-persistence/package.json ./packages/workflow-persistence/package.json
44-
COPY packages/workflow-types/package.json ./packages/workflow-types/package.json
45-
46-
# Install dependencies, then rebuild isolated-vm for Node.js
47-
# Use --linker=hoisted for flat node_modules layout (required for Docker multi-stage builds)
48-
# JOBS=4 caps node-gyp parallelism — higher values OOM isolated-vm (laverdet/isolated-vm#428)
32+
# Pruned manifests + lockfile from the pruner stage. This layer only invalidates
33+
# when package.json/bun.lock content changes — not on source edits.
34+
COPY --from=pruner /app/out/json/ ./
35+
COPY --from=pruner /app/out/bun.lock ./bun.lock
36+
37+
# Install all dependencies (including devDependencies — tailwindcss/postcss are
38+
# devDeps but required at build time). Then rebuild isolated-vm against Node.js.
39+
# JOBS=4 caps node-gyp parallelism — higher values OOM isolated-vm (laverdet/isolated-vm#428).
4940
RUN --mount=type=cache,id=bun-cache,target=/root/.bun/install/cache \
5041
--mount=type=cache,id=npm-cache,target=/root/.npm \
51-
HUSKY=0 bun install --omit=dev --ignore-scripts --linker=hoisted && \
42+
HUSKY=0 bun install --ignore-scripts --linker=hoisted && \
5243
cd node_modules/isolated-vm && JOBS=4 npx node-gyp rebuild --release
5344

5445
# ========================================
@@ -58,37 +49,11 @@ FROM base AS builder
5849
ARG TARGETPLATFORM
5950
WORKDIR /app
6051

61-
# Install turbo globally (cached for fast reinstall)
62-
RUN --mount=type=cache,id=bun-cache,target=/root/.bun/install/cache \
63-
bun install -g turbo
64-
6552
# Copy node_modules from deps stage (cached if dependencies don't change)
6653
COPY --from=deps /app/node_modules ./node_modules
6754

68-
# Copy package configuration files (needed for build)
69-
COPY package.json bun.lock turbo.json ./
70-
COPY apps/sim/package.json ./apps/sim/package.json
71-
COPY packages/audit/package.json ./packages/audit/package.json
72-
COPY packages/db/package.json ./packages/db/package.json
73-
COPY packages/logger/package.json ./packages/logger/package.json
74-
COPY packages/realtime-protocol/package.json ./packages/realtime-protocol/package.json
75-
COPY packages/security/package.json ./packages/security/package.json
76-
COPY packages/testing/package.json ./packages/testing/package.json
77-
COPY packages/tsconfig/package.json ./packages/tsconfig/package.json
78-
COPY packages/utils/package.json ./packages/utils/package.json
79-
COPY packages/workflow-authz/package.json ./packages/workflow-authz/package.json
80-
COPY packages/workflow-persistence/package.json ./packages/workflow-persistence/package.json
81-
COPY packages/workflow-types/package.json ./packages/workflow-types/package.json
82-
83-
# Copy workspace configuration files (needed for turbo)
84-
COPY apps/sim/next.config.ts ./apps/sim/next.config.ts
85-
COPY apps/sim/tsconfig.json ./apps/sim/tsconfig.json
86-
COPY apps/sim/tailwind.config.ts ./apps/sim/tailwind.config.ts
87-
COPY apps/sim/postcss.config.mjs ./apps/sim/postcss.config.mjs
88-
89-
# Copy source code (changes most frequently - placed last to maximize cache hits)
90-
COPY apps/sim ./apps/sim
91-
COPY packages ./packages
55+
# Copy pruned source tree (apps/sim + workspace packages it depends on)
56+
COPY --from=pruner /app/out/full/ ./
9257

9358
ENV NEXT_TELEMETRY_DISABLED=1 \
9459
VERCEL_TELEMETRY_DISABLED=1 \
@@ -164,4 +129,4 @@ EXPOSE 3000
164129
ENV PORT=3000 \
165130
HOSTNAME="0.0.0.0"
166131

167-
CMD ["bun", "apps/sim/server.js"]
132+
CMD ["bun", "apps/sim/server.js"]

0 commit comments

Comments
 (0)