Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

perf(docker): shrink web and worker images by dropping unused dependencies and files (#16862)

Tobias Wochingerb0955b45afc4
diff --git a/packages/shared/AGENTS.md b/packages/shared/AGENTS.md
index 9932bf012b..96c670c874 100644
--- a/packages/shared/AGENTS.md
+++ b/packages/shared/AGENTS.md
@@ -352,6 +352,7 @@ the same PR.
cron pattern, append the old pattern to `previousPatterns` so the legacy
md5-keyed schedule is cleaned up on boot.
- Do not hand-edit generated artifacts under `prisma/generated/*` or `dist/*`.
+- `next-auth` is a devDependency: import it with `import type` only. `pnpm deploy --prod` leaves it out of the worker image, so a value import would crash the worker at startup; `oxlint.config.mts` rejects one via `no-restricted-imports`.
- `src/server/ee/*` is under the Enterprise License (root `LICENSE`), not MIT.
Put EE logic there when both `web` and `worker` must import it; keep OSS
code paths out of it.
diff --git a/packages/shared/oxlint.config.mts b/packages/shared/oxlint.config.mts
index 6031c491ee..207d621ae8 100644
--- a/packages/shared/oxlint.config.mts
+++ b/packages/shared/oxlint.config.mts
@@ -30,6 +30,26 @@ const config: OxlintConfig = {
],
rules: { "@repo/no-internal-barrel-files": "off" },
},
+ {
+ files: ["**/*"],
+ rules: {
+ // The native rule (unlike the eslint-js port web uses) also checks
+ // dynamic imports and supports allowTypeImports.
+ "no-restricted-imports": [
+ "error",
+ {
+ patterns: [
+ {
+ regex: "^next-auth(/|$)",
+ allowTypeImports: true,
+ message:
+ "next-auth is a devDependency of @langfuse/shared, so `pnpm deploy --prod` leaves it out of the worker image. Use `import type`; a value import crashes the worker at startup.",
+ },
+ ],
+ },
+ ],
+ },
+ },
],
};
diff --git a/packages/shared/package.json b/packages/shared/package.json
index 9427ef8fc8..700115d9df 100644
--- a/packages/shared/package.json
+++ b/packages/shared/package.json
@@ -277,7 +277,6 @@
"lodash": "^4.18.1",
"lossless-json": "^4.1.1",
"lru-cache": "^11.2.7",
- "next-auth": "^4.24.14",
"nodemailer": "^10.1.7",
"oci-common": "^2.140.0",
"oci-objectstorage": "^2.140.0",
@@ -297,6 +296,7 @@
"@types/nodemailer": "^8.0.1",
"@types/react": "19.2.14",
"dotenv-cli": "^7.4.4",
+ "next-auth": "^4.24.14",
"prisma": "^6.19.3",
"tsx": "^4.20.5",
"typescript": "catalog:",
diff --git a/packages/shared/src/server/services/email/passwordReset/sendResetPasswordVerificationRequest.tsx b/packages/shared/src/server/services/email/passwordReset/sendResetPasswordVerificationRequest.tsx
index 0ac2053e1a..f0f0fb0db6 100644
--- a/packages/shared/src/server/services/email/passwordReset/sendResetPasswordVerificationRequest.tsx
+++ b/packages/shared/src/server/services/email/passwordReset/sendResetPasswordVerificationRequest.tsx
@@ -16,7 +16,7 @@ import {
Text,
} from "@react-email/components";
import { render } from "@react-email/render";
-import { type SendVerificationRequestParams } from "next-auth/providers/email";
+import type { SendVerificationRequestParams } from "next-auth/providers/email";
import { createMailTransport } from "../transport";
interface ResetPasswordTemplateProps {
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 857734f593..1fff463c26 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -41,6 +41,8 @@ overrides:
[email protected]>@next/env: 16.4.2
'@react-email/render>html-to-text': 10.0.1
'@ag-ui/[email protected]>@copilotkit/runtime': '-'
+ '@ag-ui/[email protected]>@mastra/client-js': '-'
+ '@prisma/client>prisma': '-'
browserslist: 4.28.7
postcss: 8.5.25
esbuild: 0.28.1
@@ -354,7 +356,7 @@ importers:
version: 2.9.0(@opentelemetry/[email protected])
'@prisma/client':
specifier: ^6.19.3
- version: 6.19.3(@typescript/[email protected])([email protected](@typescript/[email protected])([email protected]))
+ version: 6.19.3(@typescript/[email protected])
'@react-email/components':
specifier: ^0.5.1
@@ -427,9 +429,6 @@ importers:
lru-cache:
specifier: ^11.2.7
version: 11.2.7
- next-auth:
- specifier: ^4.24.14
- version: 4.24.15(patch_hash=298683aaa31566643f1899990a065b342ad777d8613f50a25ddc44dd46fb5b4d)([email protected](@babel/[email protected]([email protected]))(@opentelemetry/[email protected])(@playwright/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected]))([email protected])([email protected]([email protected]))([email protected])
nodemailer:
specifier: ^10.1.7
version: 10.1.7
@@ -485,6 +484,9 @@ importers:
dotenv-cli:
specifier: ^7.4.4
version: 7.4.4
+ next-auth:
+ specifier: ^4.24.14
+ version: 4.24.15(patch_hash=298683aaa31566643f1899990a065b342ad777d8613f50a25ddc44dd46fb5b4d)([email protected](@babel/[email protected]([email protected]))(@opentelemetry/[email protected])(@playwright/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected]))([email protected])([email protected]([email protected]))([email protected])
prisma:
specifier: ^6.19.3
version: 6.19.3(@typescript/[email protected])([email protected])
@@ -583,7 +585,7 @@ importers:
'@next-auth/prisma-adapter':
specifier: ^1.0.7
'@opentelemetry/api':
specifier: ^1.9.1
version: 1.9.1
@@ -1103,7 +1105,7 @@ importers:
version: 0.0.52
'@ag-ui/mastra':
specifier: 1.1.1
'@anthropic-ai/tokenizer':
specifier: ^0.0.4
version: 0.0.4
@@ -1166,7 +1168,7 @@ importers:
version: 0.220.0(@opentelemetry/[email protected])([email protected])
'@prisma/client':
specifier: ^6.19.3
- version: 6.19.3(@typescript/[email protected])([email protected](@typescript/[email protected])([email protected]))
+ version: 6.19.3(@typescript/[email protected])
'@prisma/instrumentation':
specifier: ^6.19.3
version: 6.19.3(@opentelemetry/[email protected])([email protected])
@@ -1333,7 +1335,6 @@ packages:
peerDependencies:
'@ag-ui/client': '>=0.0.44'
'@ag-ui/core': '>=0.0.44'
- '@mastra/client-js': '>=1.0.0-0 <2.0.0-0'
'@mastra/core': '>=1.29.0 <2.0.0-0'
@@ -2822,18 +2823,6 @@ packages:
'@marijn/[email protected]':
resolution: {integrity: sha512-l0h88YhZFyKdXIFNfSWpyjStDjGHwZ/U7iobcK1cQQD8sejsONdQtTVU+1wVN1PBw40PiiHB1vA5S7VTfQiP9g==}
- '@mastra/[email protected]':
- resolution: {integrity: sha512-sp40SwMQnoCoLu4uu7hYnzlAl279DQTiiazvlAt54dFvzykkqZSQaDOn+gBA4XDtgCQBk4o4WD10SkORo2BQFQ==}
- engines: {node: '>=22.13.0'}
- peerDependencies:
- zod: 4.6.6
-
- '@mastra/[email protected]':
- resolution: {integrity: sha512-0Fm1nOpTTcqYIpbipj8bWYGc9vjaJcKWxAK5X7kP177ijjdmSUQuM5Zk6RNYb6+LB4RmgdOdyWOKS4Rb4Ih1+w==}
- engines: {node: '>=22.13.0'}
- peerDependencies:
- zod: 4.6.6
-
'@mastra/[email protected]':
resolution: {integrity: sha512-8w0O+7R9L125svWXHkTVLdHGjaWhvmJAJKfmvSLjgTfK0q0FZI29JlrCwcjqwY1kQTqb1yPzk6GJXh8xrJXiFA==}
engines: {node: '>=22.13.0'}
@@ -2846,12 +2835,6 @@ packages:
peerDependencies:
'@mastra/core': '>=1.0.0-0 <2.0.0-0'
- '@mastra/[email protected]':
- resolution: {integrity: sha512-8Fg8PeO7GsRPOrEZAzc5udZgsF9ZDxih5JSoxjgnR79d0ImjKffhcoysPW6wIYXPEZ5i6/QDNR7rCazZZSD5Tg==}
- engines: {node: '>=22.13.0'}
- peerDependencies:
- zod: 4.6.6
-
'@mastra/[email protected]':
resolution: {integrity: sha512-VAWCXGuWuTqnljkheb3zKUujNK6rdGhFISxdSoSz3/d3HJWZOHY10mUnXw5lg0s73FdFDGg4tehbq28fAZz+lA==}
engines: {node: '>=22.13.0'}
@@ -4786,11 +4769,8 @@ packages:
resolution: {integrity: sha512-mKq3jQFhjvko5LTJFHGilsuQs+W+T3Gm451NzuTDGQxwCzwXHYnIu2zGkRoW+Exq3Rob7yp2MfzSrdIiZVhrBg==}
engines: {node: '>=18.18'}
peerDependencies:
- prisma: '*'
typescript: '>=5.1.0'
peerDependenciesMeta:
- prisma:
- optional: true
typescript:
optional: true
@@ -6104,67 +6084,6 @@ packages:
resolution: {integrity: sha512-zpHIvgr2NWASkgWgv1O0zPPX7VFdkHKa9NxxjGseGvSY2DRZgRsnoXuEcjETwPeqP92blsINwfbIJz0F0/0Skg==}
engines: {node: '>=18.0.0'}
- '@standard-community/[email protected]':
- resolution: {integrity: sha512-4+ZPorwDRt47i+O7RjyuaxHRK/37QY/LmgxlGrRrSTLYoFatEOzvqIc85GTlM18SFZ5E91C+v0o/M37wZPpUHA==}
- peerDependencies:
- '@standard-schema/spec': ^1.0.0
- '@types/json-schema': ^7.0.15
- '@valibot/to-json-schema': ^1.3.0
- arktype: ^2.1.20
- effect: ^3.16.8
- quansync: ^0.2.11
- sury: ^10.0.0
- typebox: ^1.0.17
- valibot: ^1.1.0
- zod: 4.6.6
- zod-to-json-schema: ^3.24.5
- peerDependenciesMeta:
- '@valibot/to-json-schema':
- optional: true
- arktype:
- optional: true
- effect:
- optional: true
- sury:
- optional: true
- typebox:
- optional: true
- valibot:
- optional: true
- zod:
- optional: true
- zod-to-json-schema:
- optional: true
-
- '@standard-community/[email protected]':
- resolution: {integrity: sha512-htj+yldvN1XncyZi4rehbf9kLbu8os2Ke/rfqoZHCMHuw34kiF3LP/yQPdA0tQ940y8nDq3Iou8R3wG+AGGyvg==}
- peerDependencies:
- '@standard-community/standard-json': ^0.3.5
- '@standard-schema/spec': ^1.0.0
- arktype: ^2.1.20
- effect: ^3.17.14
- openapi-types: ^12.1.3
- sury: ^10.0.0
- typebox: ^1.0.0
- valibot: ^1.1.0
- zod: 4.6.6
- zod-openapi: ^4
- peerDependenciesMeta:
- arktype:
- optional: true
- effect:
- optional: true
- sury:
- optional: true
- typebox:
- optional: true
- valibot:
- optional: true
- zod:
- optional: true
- zod-openapi:
- optional: true
-
'@standard-schema/[email protected]':
resolution: {integrity: sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w==}
@@ -7657,9 +7576,6 @@ packages:
resolution: {integrity: sha512-TITQPUkaz+aVk5GL6NhOdwk1aEaNTSDPsGFWrTuhKGtjTF70jL/Oht2W4c6rXUe5fu7Ie19VIahAXHIIiWWNeg==}
- resolution: {integrity: sha512-0CNTVCLZggSh7bc5VkX5WWPWO+cyZbNd07IHIsSXLia/eAq+r836hgk+8BKoEh7949Mda87VUOitx5OddVj64A==}
-
resolution: {integrity: sha512-eyrF0jiFpY+3drT6383f1qhkbGsLSifNAjA61IUjZjmLCWjItY6LB9ft9YhoDgwfmclB2zhu51Lc7+95b8NRAg==}
@@ -9075,21 +8991,6 @@ packages:
resolution: {integrity: sha512-nbfWpyRMcMrPMmDwJB+dhX/eiaPKtc2RB+0QZskqJ3WjRA/FDS0e9hZrx8EC/lbEv8gXy98FcDbNa/dspAaJMg==}
engines: {node: '>=12.0.0'}
- resolution: {integrity: sha512-xDvCWpWEIv0weEmnl3EjRQzqbHIO8LnfzMuYOCmbuyE5aes6aXxLg4vM3ybnoZD5TiTUkA6PuRQPJs3R7WRBig==}
- peerDependencies:
- '@hono/standard-validator': ^0.2.0
- '@standard-community/standard-json': ^0.3.5
- '@standard-community/standard-openapi': ^0.2.9
- '@types/json-schema': ^7.0.15
- hono: 4.13.11
- openapi-types: ^12.1.3
- peerDependenciesMeta:
- '@hono/standard-validator':
- optional: true
- hono:
- optional: true
-
resolution: {integrity: sha512-/SMX/RQNJn7oNmFwH6DtwDqcrzZU2otm1FD6OJe2cWF6cfy/F8hq0XVBv7xW3FTJshRQwuBnXHDq2kNsdZnshg==}
engines: {node: '>=16.9.0'}
@@ -10443,9 +10344,6 @@ packages:
resolution: {integrity: sha512-smsWv2LzFjP03xmvFoJ331ss6h+jixfA4UUV/Bsiyuu4YJPfN+FIQGOIiv4w9/+MoHkfkJ22UIaQWRVFRfH6Vw==}
engines: {node: '>=20'}
- resolution: {integrity: sha512-N4YtSYJqghVu4iek2ZUvcN/0aqH1kRDuNqzcycDxhOUpg7GdvLa2F3DgS6yBNhInhv2r/6I0Flkn7CqL8+nIcw==}
-
resolution: {integrity: sha512-jDBPgSVfTnkIh71Hg9pRvtJc6wTwqjRkN88+gCFtYWrlP4Yx2Dsrow8uPi3qLr/aeymPF3o2+dS+wOpglK04ew==}
@@ -12567,13 +12465,12 @@ snapshots:
'@ag-ui/core': 0.0.52
'@ag-ui/proto': 0.0.52
dependencies:
'@ag-ui/a2ui-toolkit': 0.0.4
'@ag-ui/client': 0.0.52
'@ag-ui/core': 0.0.52
'@ai-sdk/ui-utils': 1.2.11([email protected])
fast-json-patch: 3.1.1
rxjs: 7.8.1
@@ -14410,82 +14307,6 @@ snapshots:
'@marijn/[email protected]': {}
- dependencies:
- '@ai-sdk/ui-utils': 1.2.11([email protected])
- '@lukeed/uuid': 2.0.1
- '@mastra/schema-compat': 1.2.10([email protected])
- canonicalize: 1.0.8
- jose: 6.2.3
- json-schema: 0.4.0
- zod: 4.6.6
- transitivePeerDependencies:
- - '@bufbuild/protobuf'
- - '@cfworker/json-schema'
- - '@grpc/grpc-js'
- - '@hono/standard-validator'
- - '@standard-community/standard-json'
- - '@standard-community/standard-openapi'
- - '@types/json-schema'
- - ai
- - bufferutil
- - express
- - openapi-types
- - rxjs
- - supports-color
- - utf-8-validate
-
- dependencies:
- '@ai-sdk/provider-utils-v5': '@ai-sdk/[email protected]([email protected])'
- '@ai-sdk/provider-utils-v6': '@ai-sdk/[email protected]([email protected])'
- '@ai-sdk/provider-v5': '@ai-sdk/[email protected]'
- '@ai-sdk/provider-v6': '@ai-sdk/[email protected]'
- '@ai-sdk/ui-utils-v5': '@ai-sdk/[email protected]([email protected])'
- '@isaacs/ttlcache': 2.1.5
- '@lukeed/uuid': 2.0.1
- '@mastra/schema-compat': 1.2.10([email protected])
- '@modelcontextprotocol/sdk': 1.32.0(@cfworker/[email protected])([email protected])([email protected])
- '@sindresorhus/slugify': 2.2.1
- '@standard-schema/spec': 1.1.0
- ajv: 8.20.0
- croner: 10.0.1
- dotenv: 17.4.2
- execa: 9.6.1
- fastq: 1.20.1
- gray-matter: 4.0.3
- hono: 4.13.11
- ignore: 7.0.6
- json-schema: 0.4.0
- lru-cache: 11.2.7
- p-map: 7.0.4
- p-retry: 7.1.1
- picomatch: 4.0.5
- posthog-node: 5.49.1([email protected])
- tokenx: 1.3.0
- ws: 8.21.3
- xxhash-wasm: 1.1.0
- zod: 4.6.6
- transitivePeerDependencies:
- - '@bufbuild/protobuf'
- - '@cfworker/json-schema'
- - '@grpc/grpc-js'
- - '@hono/standard-validator'
- - '@standard-community/standard-json'
- - '@standard-community/standard-openapi'
- - '@types/json-schema'
- - ai
- - bufferutil
- - express
- - openapi-types
- - rxjs
- - supports-color
- - utf-8-validate
-
dependencies:
@@ -14543,14 +14364,6 @@ snapshots:
- supports-color
- zod
- dependencies:
- json-schema-to-zod: 2.8.1
- zod: 4.6.6
- zod-from-json-schema: 0.5.2
- zod-from-json-schema-v3: [email protected]
- zod-to-json-schema: 3.25.2([email protected])
-
dependencies:
json-schema-to-zod: 2.8.1
@@ -14983,9 +14796,9 @@ snapshots:
'@napi-rs/wasm-tools-win32-ia32-msvc': 1.1.0
'@napi-rs/wasm-tools-win32-x64-msvc': 1.1.0
dependencies:
+ '@prisma/client': 6.19.3([email protected])
next-auth: 4.24.15(patch_hash=298683aaa31566643f1899990a065b342ad777d8613f50a25ddc44dd46fb5b4d)([email protected](@babel/[email protected]([email protected]))(@opentelemetry/[email protected])(@playwright/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected]))([email protected])([email protected]([email protected]))([email protected])
'@next/[email protected]': {}
@@ -15976,14 +15789,12 @@ snapshots:
'@posthog/[email protected]': {}
+ '@prisma/[email protected](@typescript/[email protected])':
optionalDependencies:
- prisma: 6.19.3(@typescript/[email protected])([email protected])
typescript: '@typescript/[email protected]'
optionalDependencies:
typescript: 7.0.2
@@ -17511,25 +17322,6 @@ snapshots:
'@smithy/core': 3.30.0
tslib: 2.8.1
- dependencies:
- '@standard-schema/spec': 1.1.0
- '@types/json-schema': 7.0.15
- quansync: 0.2.11
- optionalDependencies:
- effect: 3.21.0
- zod: 4.6.6
- zod-to-json-schema: 3.25.2([email protected])
-
- dependencies:
- '@standard-schema/spec': 1.1.0
- openapi-types: 12.1.3
- optionalDependencies:
- effect: 3.21.0
- zod: 4.6.6
-
'@standard-schema/[email protected]': {}
'@standard-schema/[email protected]': {}
@@ -19160,8 +18952,6 @@ snapshots:
-
@@ -20847,15 +20637,6 @@ snapshots:
- dependencies:
- '@types/json-schema': 7.0.15
- openapi-types: 12.1.3
- optionalDependencies:
- hono: 4.13.11
-
@@ -22444,8 +22225,6 @@ snapshots:
powershell-utils: 0.1.0
wsl-utils: 0.3.1
-
dependencies:
jose: 4.15.9
@@ -22936,16 +22715,6 @@ snapshots:
transitivePeerDependencies:
- magicast
- dependencies:
- '@prisma/config': 6.19.3([email protected])
- '@prisma/engines': 6.19.3
- optionalDependencies:
- typescript: 7.0.2
- transitivePeerDependencies:
- - magicast
- optional: true
-
diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml
index ea93f5faf6..a3a2477a66 100644
--- a/pnpm-workspace.yaml
+++ b/pnpm-workspace.yaml
@@ -104,6 +104,14 @@ overrides:
# The root Mastra adapter does not load CopilotKit. Only its unused
# `@ag-ui/mastra/copilotkit` subpath requires this peer.
"@ag-ui/[email protected]>@copilotkit/runtime": "-"
+ # The adapter only drives local agents and never requires the remote-agent
+ # client at runtime (its types import MastraClient). Auto-installing this peer
+ # added @mastra/client-js, which pins a second, older @mastra/core (~60MB).
+ "@ag-ui/[email protected]>@mastra/client-js": "-"
+ # The generated client loads its query engine from .prisma/client and never
+ # requires the CLI. Resolving this optional peer made `pnpm deploy --prod`
+ # ship the Prisma CLI and its engines in the worker image.
+ "@prisma/client>prisma": "-"
browserslist: 4.28.7
postcss: 8.5.25
esbuild: "0.28.1"
diff --git a/scripts/docker/prune-node-modules.sh b/scripts/docker/prune-node-modules.sh
new file mode 100755
index 0000000000..6b3ea13ea5
--- /dev/null
+++ b/scripts/docker/prune-node-modules.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+# Delete files that production node_modules trees ship but never load: source
+# maps, type declarations, and Prisma's engines for databases other than
+# PostgreSQL. Used by web/Dockerfile and worker/Dockerfile before copying a
+# tree into the runtime image.
+#
+# Usage: prune-node-modules.sh DIR...
+set -eu
+
+if [ "$#" -eq 0 ]; then
+ echo "usage: $0 DIR..." >&2
+ exit 1
+fi
+for dir in "$@"; do
+ if [ ! -d "$dir" ]; then
+ echo "$0: not a directory: $dir" >&2
+ exit 1
+ fi
+done
+
+find "$@" -type f \( \
+ -name '*.js.map' -o -name '*.mjs.map' -o -name '*.cjs.map' \
+ -o -name '*.d.ts.map' -o -name '*.d.ts' -o -name '*.d.mts' -o -name '*.d.cts' \
+ -o -name 'query_*_bg.mysql.*' -o -name 'query_*_bg.sqlite.*' \
+ -o -name 'query_*_bg.sqlserver.*' -o -name 'query_*_bg.cockroachdb.*' \
+ \) -delete
diff --git a/web/Dockerfile b/web/Dockerfile
index 13cc485bda..7c63b10802 100644
--- a/web/Dockerfile
+++ b/web/Dockerfile
@@ -108,12 +108,21 @@ COPY --from=rpm-installer /mnt/rootfs /
# prisma CLI + optional dd-trace are npm-installed here and copied into the
# package-manager-less runtime image.
FROM --platform=${TARGETPLATFORM:-linux/amd64} build-base AS web-tools
-RUN npm install -g --prefix /opt/prisma-cli --no-package-lock --no-save [email protected]
+COPY scripts/docker/prune-node-modules.sh /usr/local/bin/prune-node-modules
+# entrypoint.sh only runs `prisma db execute` and `prisma migrate deploy`, which
+# need neither the client generator nor Studio. Keep @prisma/engines intact:
+# the CLI re-downloads any missing engine at startup, which fails as non-root
+# and without network access.
+RUN npm install -g --prefix /opt/prisma-cli --no-package-lock --no-save [email protected] && \
+ rm -rf /opt/prisma-cli/lib/node_modules/prisma/prisma-client \
+ /opt/prisma-cli/lib/node_modules/prisma/build/public && \
+ prune-node-modules /opt/prisma-cli/lib/node_modules
ARG NEXT_PUBLIC_LANGFUSE_CLOUD_REGION
RUN mkdir -p /opt/dd/node_modules && \
if [ -n "$NEXT_PUBLIC_LANGFUSE_CLOUD_REGION" ]; then \
cd /opt/dd && npm install --no-package-lock --no-save [email protected]; \
- fi
+ fi && \
+ prune-node-modules /opt/dd/node_modules
FROM --platform=${BUILDPLATFORM} golang:1.26 AS migrate-builder
ARG TARGETOS
@@ -244,6 +253,12 @@ ENV CI true
RUN NODE_OPTIONS='--max-old-space-size-percentage=75' turbo run build --filter=web...
+# Next copies .next/server/pages into the standalone output wholesale, including
+# the *.nft.json build traces (~300MB) that server.js never reads.
+COPY scripts/docker/prune-node-modules.sh /usr/local/bin/prune-node-modules
+RUN find ./web/.next/standalone -type f -name '*.nft.json' -delete && \
+ prune-node-modules ./web/.next/standalone/node_modules
+
# Production image, copy all the files and run next
FROM --platform=${TARGETPLATFORM:-linux/amd64} runtime-base AS runner
diff --git a/worker/Dockerfile b/worker/Dockerfile
index 302604e7ac..75e03fe271 100644
--- a/worker/Dockerfile
+++ b/worker/Dockerfile
@@ -200,9 +200,8 @@ FROM --platform=${TARGETPLATFORM:-linux/amd64} builder AS prod-deps
# previously we copied the --from=builder /app . (includes full node_modules etc)
# we only need the prod + generated prisma client plus .prisma artifacts
-# @langfuse/shared still pulls in next-auth transitively, so keep the deploy output
-# intact here instead of pruning node_modules in Docker.
# pnpm deploy materializes linked workspace packages into the standalone artifact.
+COPY scripts/docker/prune-node-modules.sh /usr/local/bin/prune-node-modules
RUN pnpm --filter worker deploy --prod /prod/worker && \
builder_prisma_client_dir="$(find /app/node_modules/.pnpm -path '*/node_modules/@prisma/client' -type d | head -n 1)" && \
deployed_prisma_client_dir="$(find /prod/worker/node_modules/.pnpm -path '*/node_modules/@prisma/client' -type d | head -n 1)" && \
@@ -210,7 +209,16 @@ RUN pnpm --filter worker deploy --prod /prod/worker && \
deployed_prisma_runtime_dir="$(dirname "$(dirname "$deployed_prisma_client_dir")")/.prisma" && \
rm -rf "$deployed_prisma_client_dir" "$deployed_prisma_runtime_dir" && \
cp -R "$builder_prisma_client_dir" "$deployed_prisma_client_dir" && \
- cp -R "$builder_prisma_runtime_dir" "$deployed_prisma_runtime_dir"
+ cp -R "$builder_prisma_runtime_dir" "$deployed_prisma_runtime_dir" && \
+ prune-node-modules /prod/worker/node_modules
+
+# Next.js with its SWC compiler and the Prisma CLI with its engines add ~400MB
+# and are never loaded by the worker. They used to arrive through next-auth in
+# @langfuse/shared and the optional prisma peer of @prisma/client.
+RUN if ls /prod/worker/node_modules/.pnpm | grep -E '^(next|prisma|@prisma\+engines)@'; then \
+ echo "worker deploy output contains Next.js or the Prisma CLI (see 'pnpm --filter worker why <pkg> --prod')" >&2; \
+ exit 1; \
+ fi
FROM --platform=${TARGETPLATFORM:-linux/amd64} runtime-base AS runner