Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
431 lines (402 loc) · 27.7 KB
/
Copy pathDockerfile
File metadata and controls
431 lines (402 loc) · 27.7 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
# syntax=docker/dockerfile:1
# ── Full-stack single-container image for Platform ────────────────────────────
#
# Runs the backend (server.js) in ONE container via the supervisor
# (scripts/start.js → local-services.js → supervisor/lifecycle.js), exactly like
# `npm start` does locally. dsh's native plugins cover LLM routing and SaaS
# connectors, so there are no sidecar processes.
#
# docker build -t your-registry/platform .
# docker run -p 3000:3000 -v platform-data:/data your-registry/platform
#
# Multi-stage: the builder compiles native addons + builds web/dist; the runtime
# stage copies only what is needed. Node 25 is used in BOTH stages: the same major
# the release.yml CI uses, AND the lockfile was generated under npm 11 (Node 22's
# npm 10 misreads it — "Missing: zod@... from lock file"). The system Node ABI then
# matches the native addons compiled at `npm ci` time (better-sqlite3, tree-sitter).
#
# `npm run predist` is deliberately NOT run here. It builds resources/node — the
# standalone Node the *desktop* bundle needs — while the supervisor runs server.js
# on the system Node (process.execPath: this image's own Node), so nothing in the
# container would use it. It is also a 53 MB download from nodejs.org that stalls
# from the China build host.
# ── Base image ───────────────────────────────────────────────────────────────
# A build arg because the two build hosts have opposite network access: the
# GitHub runner (docker-deploy.yml) reaches Docker Hub, while the China build
# host cannot reach registry-1.docker.io and pulls
# a registry mirror instead — its CI passes that as
# BASE_IMAGE. Declared before the first FROM so both stages can use it.
ARG BASE_IMAGE=node:25-bookworm-slim
# ── Builder ──────────────────────────────────────────────────────────────────
FROM ${BASE_IMAGE} AS builder
# python3/make/g++ for native addons (better-sqlite3); curl + tar for
# build-node, which curls the Node standalone release tarball and extracts it.
# deb.debian.org crawls at ~130KB/s from the China build host (mirrors.aliyun.com
# is 100x faster); swap before any apt fetch in both stages.
RUN sed -i 's|deb.debian.org|mirrors.aliyun.com|g' /etc/apt/sources.list.d/debian.sources \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
python3 make g++ ca-certificates git curl tar \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Bound every build-time Node process. The China build host
# is memory-constrained and shares the node with other workloads: a build that spikes past its
# free memory makes the kernel OOM-kill kubelet and the node's registry/proxy —
# node NotReady, site 502 — which happened twice on 2026-09-21. A build that needs
# more than this cap fails HERE, which is recoverable, instead of taking the
# deployment down with it. (The web build peaks well under 1GB; measured.)
ENV NODE_OPTIONS=--max-old-space-size=1024 \
npm_config_jobs=1 \
UV_THREADPOOL_SIZE=2
# Install root + web deps first (cacheable layer). --ignore-scripts skips the
# package.json postinstall hook (node scripts/postinstall-web.js && …postinstall-bundle.js):
# at this layer only package*.json is copied, so scripts/ doesn't exist yet and the hook
# would throw "Cannot find module" before the PLATFORM_SKIP_* env guard can exit 0. We run
# the web build + resource builds explicitly below, so the postinstall is redundant here —
# AND making it best-effort (postinstall-bundle.js never fails `npm install`) would mask a
# broken resource build that should fail the docker build.
COPY package*.json ./
COPY web/package*.json ./web/
# The facet thin SPA (add-facet-platform) has its own dep tree; same pattern —
# install early for cache, build after `COPY . .`.
COPY facet/web/package*.json ./facet/web/
# --omit=dev on the ROOT tree only: the runtime (scripts/start.js → server.js)
# never imports a devDependency, and they were ~330 MB of dead weight — the
# electron binary alone is 299 MB in what is a server-only image. The WEB ci
# below must keep devDeps: vite is one, and the image builds web/dist itself.
# Native addons (better-sqlite3/tree-sitter) ship prebuilt binaries, so
# --ignore-scripts + omit=dev compose safely.
# --legacy-peer-deps RETIRED (ADR-0023): it existed because the dsh rows mixed
# two peer generations; since the 0.2.0 unified generation every dsh row is one
# lockstep version with no peers to reconcile. A bare npm ci is itself the
# regression probe — a future generation mix fails HERE, at build time.
RUN npm ci --omit=dev --ignore-scripts \
&& npm --prefix web ci --ignore-scripts \
&& npm --prefix facet/web ci --ignore-scripts
# dsh-profile-template/ is consumed by the dsh install layer below (cp →
# /opt/dsh-home), so it must exist in the builder BEFORE that RUN. Copying it
# here keeps the slow dsh install cacheable: these tiny text files change
# far less often than the source that arrives via `COPY . .` further down.
COPY dsh-profile-template/ ./dsh-profile-template/
# dsh-matrix/ — the single version truth for the dsh runtime (ADR-0007/0023,
# add-dsh-matrix-lock): since the 0.2.0 unified generation the manifest is the
# dsh row alone (the whole family ships as exact-pinned hard deps of one
# lockstep version; overrides and the cordis-plugin-hmr pin retired). The
# prune list + pruner ride the same layer: after npm ci they remove the
# packages the platform profile provably never loads (libreoffice-kit
# binaries, dsh's own UI chrome — see dsh-matrix/prune.json), and the boot
# gate passes exactly those absences.
COPY dsh-matrix/package.json dsh-matrix/package-lock.json dsh-matrix/.npmrc dsh-matrix/prune.json dsh-matrix/prune.mjs ./dsh-matrix/
# file: dependency sources for the matrix (the plugin-supply sample bundle):
# the lock records them as links into dsh-matrix/samples, so npm ci — and the
# later /opt/dsh copy — need the real directory beside the manifest.
COPY dsh-matrix/samples/ ./dsh-matrix/samples/
# One npm ci from the frozen matrix into /opt/dsh — the ONLY real tree (the
# old second install under /opt/dsh-home/profiles/platform is gone; that
# profile keeps its scaffold files and gets a node_modules SYMLINK here — the
# same seedHome pattern agent-runner/compose.js proves in staging, so the
# hundreds-of-MB dsh-base closure is never duplicated per home).
#
# .npmrc deliberately does NOT set legacy-peer-deps (it disabled transitive
# peer auto-installation and forced the old hand-pinned rows into existence);
# npm's default peer resolution fills the closure, and the lock freezes it.
# NO --legacy-peer-deps on this line either (design D3): under npm 11 (the npm
# node:25 ships) the flag makes npm ci SKIP every lock entry marked "peer":
# true — the 24-package dsh rc.2 plugin closure vanishes from /opt/dsh and the
# boot gate refuses to start (image-publish runs 37784214791 / 37836417702:
# "missing: @deepseek-ai/dsh-scope (lock: 0.1.1-rc.2) …"). The matrix tree is
# its own resolution universe — the overrides in dsh-matrix/package.json unify
# the rc.2/rc.5 generations — so npm's default peer resolution succeeds on the
# frozen lock; verified under npm 10.9 / 11.6 / 11.12 with diffMatrixTree
# (0 missing). The ROOT tree (above) is the opposite case: it declares both
# generations side by side, so its clean install is genuinely ERESOLVE and the
# flag is required there.
# NODE_OPTIONS heap bump: npm's resolver exhausts the default 2GB heap on
# this closure. Boot-time hard gate: server.js and agent-runner verify the
# installed tree against the same lock at startup (lib/dsh-matrix-verify.js).
#
# The app-tree prune (--tree /app) rides the same RUN: the root tree
# transitively carries the dsh family (dsh-sdk-client hard-depends on dsh, so
# slimming the root manifest does NOT shrink /app — measured 2026-10-14:
# 290 @deepseek-ai packages / 219MB), and that copy includes the same prunable
# payload /opt/dsh removes (libreoffice-kit ~148MB, dsh's own UI ~38MB).
# prune.json's contract is "applies everywhere the matrix installs" — the
# image's /opt/dsh, the contracts scratch tree, and the desktop's predist
# install; the app tree is the fourth site and was the one missing.
# `cd`, not `--prefix`: npm 11.20.0 fails on an ABSOLUTE prefix
# (`Missing: <dir>@0.0.0 from lock file`; relative prefixes and a `cd` both
# work — three-way measurement in ci.yml's bootstrap note). The subshell keeps
# the chain's relative paths: prune.mjs runs from WORKDIR, as before.
RUN mkdir -p /opt/dsh \
&& cp dsh-matrix/package.json dsh-matrix/package-lock.json dsh-matrix/.npmrc /opt/dsh/ \
&& cp -r dsh-matrix/samples /opt/dsh/samples \
&& (cd /opt/dsh && NODE_OPTIONS=--max-old-space-size=8192 npm ci) \
&& node dsh-matrix/prune.mjs --tree /opt/dsh \
&& node dsh-matrix/prune.mjs --tree /app \
&& mkdir -p /opt/dsh-home/profiles/platform \
&& cp dsh-profile-template/package.json \
dsh-profile-template/pnpm-workspace.yaml \
dsh-profile-template/cordis.yml \
dsh-profile-template/cordis.patch.yml \
/opt/dsh-home/profiles/platform/ \
&& ln -s /opt/dsh/node_modules /opt/dsh-home/profiles/platform/node_modules
# Second harness (add-harness-adapter D3): claude-code-acp into its own npm
# prefix — an ACP-speaking agent the runner can host beside dsh
# (agent-runner/harness/acp.js drives it over stdio; AGENT_RUNNER_ACP_COMMANDS
# allowlists the binary name). A SEPARATE prefix, never merged into /opt/dsh:
# the ACP closure (Claude Agent SDK + its bundled CLI, ~80MB unpacked) must
# not enter the dsh matrix's version discipline, and a future harness upgrade
# rolls this one layer. --ignore-scripts: the SDK's postinstall only prints
# notices; the binary is plain JS. The install is pinned exactly (no range).
RUN mkdir -p /opt/harness-acp \
&& npm install --prefix /opt/harness-acp --omit=dev --ignore-scripts --no-audit --no-fund \
@zed-industries/claude-code-acp@0.16.2 \
&& ln -s /opt/harness-acp/node_modules/.bin/claude-code-acp /usr/local/bin/claude-code-acp
# Browser lane (add-browser-use-lane): @playwright/mcp + chromium in their own
# prefix — the same pattern as /opt/harness-acp, never merged into /opt/dsh
# (not part of the dsh version discipline). The pin matches the version the
# upstream dsh provider ships (0.2.1 line pins @playwright/mcp 0.0.80), so the
# future A2 official bundle swaps implementation, not tool semantics.
#
# STAGE SPLIT (2026-10-28, first roll caught it): this stage installs the
# BROWSER BINARIES only; both the prefix and the three BROWSER_* env vars must
# land in the RUNTIME stage (see its COPY/ENV block) — an ENV here or a missing
# COPY ships an image that declares no lane, which the image smoke then
# honestly SKIPs instead of failing. The chromium SYSTEM libraries come from
# `playwright install-deps chromium` in the runtime stage (apt state does not
# cross stages). ~170-250MB.
ENV BROWSER_MCP_CLI=/opt/browser-mcp/node_modules/@playwright/mcp/cli.js \
BROWSER_RUNTIME_PATH=/opt/browser-mcp/ms-playwright \
PLAYWRIGHT_BROWSERS_PATH=/opt/browser-mcp/ms-playwright
RUN mkdir -p /opt/browser-mcp \
&& npm install --prefix /opt/browser-mcp --omit=dev --ignore-scripts --no-audit --no-fund \
@playwright/mcp@0.0.80 \
&& PLAYWRIGHT_BROWSERS_PATH=/opt/browser-mcp/ms-playwright \
/opt/browser-mcp/node_modules/.bin/playwright install chromium
# Copy the rest of the source. resources/ is .dockerignored: it holds only the
# platform-specific standalone Node that predist downloads, which this image does
# not build and does not use.
COPY . .
# Credential-surface gate at image build (harden-plugin-supply-gates 3.2): the
# same check the desktop's predist runs, over the declarations that compose into
# every profile (template package.json + patch layers, supply manifest, sample
# bundles). It must sit AFTER `COPY . .` — scripts/ does not exist before that.
# A hit fails the image here, before it can reach a cell: runbook S6 as a build
# gate rather than a reviewer's memory.
RUN node scripts/check-bundle-credentials.mjs
# Supply declaration gate (same change, 4.1): every composed bundle must carry a
# reviewed contribution declaration, and every declaration must compose somewhere.
RUN node scripts/check-plugin-supply.mjs
# Curation-evidence gate (add-curation-evidence-gate 3.2): the plugin catalogue
# has no HTTP write face — an entry is listed by editing the file and baking it,
# so this IS the 上架 rejection point. It BLOCKS: a supplied entry whose evidence
# is missing or expired stops the build and names the entry and the missing field.
# While the repo has no catalogue this is a no-op (exit 0) — the loop is closed
# for the FIRST entry that lands, not for a human who must remember to flip a flag.
RUN node scripts/check-curation-evidence.mjs
# Build provenance. `scripts/make-public-snapshot.mjs` writes BUILD-INFO.json into
# the snapshot tree (baseRef / baseCommit / builtAt); a build from anything else
# (the private repo, a feature branch) has no such file, and the runtime stage's
# COPY is an explicit allowlist that would then fail. So the builder guarantees
# the file: real provenance when the snapshot provided it, an honest "unknown"
# otherwise — never a fabricated sha.
RUN [ -f BUILD-INFO.json ] || printf '%s\n' \
'{"baseRef":"unknown","baseCommit":"unknown","builtAt":null}' > BUILD-INFO.json
# Build the React frontend. (No `npm run predist` — see the header note.)
#
# No `npm prune --omit=dev` here, deliberately — it was tried and it produced an
# image that dies at boot with ERR_MODULE_NOT_FOUND. @llamaindex/readers is the
# only @llamaindex package in `dependencies` and it declares @llamaindex/core as
# a peer, so prune drops the whole @llamaindex tree (core/env/openai, 344MB) even
# though readers/docx/dist/index.js imports it at load time. Same failure mode as
# the dsh peer rows above. The saving is illusory anyway: root devDependencies are
# only electron/typescript/playwright/biome (~12MB) — the web build's deps live in
# web/node_modules and are never copied to the runtime stage.
RUN npm run web:build
# The facet thin SPA (add-facet-platform): the same image serves two roles —
# the platform (default CMD) and the standalone facet service
# (`node facet/index.js`, per-deployment command override). One image keeps
# the build/relay/GitOps pipelines single-tracked; the SPA is ~500KB.
# Remove stale dist before build to bust Docker layer cache on domains.json.
RUN rm -rf facet/web/dist && npm --prefix facet/web run build
# Force-copy domains.json from source (bypasses Vite/buildx cache).
RUN cp facet/web/public/domains.json facet/web/dist/domains.json
# ── Runtime ──────────────────────────────────────────────────────────────────
FROM ${BASE_IMAGE} AS runtime
# ca-certificates for outbound HTTPS (Volces upstreams); curl for the CI image
# smoke probe (docker exec) and ops debugging; python3 + pip for the office
# execution layer (add-doc-studio: workspace-side docx/xlsx/pptx generation and
# ingestion, pinned in requirements-office.txt — see that file for why
# markitdown is NOT in the list). Everything else is bundled in
# node_modules / web/dist and needs no system packages.
RUN sed -i 's|deb.debian.org|mirrors.aliyun.com|g' /etc/apt/sources.list.d/debian.sources \
&& apt-get update \
&& apt-get install -y --no-install-recommends ca-certificates curl python3 python3-pip \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Production deps (native addons already compiled in the builder) and the built
# frontend. Ownership is applied on the way in (`--chown`) instead of with a
# recursive `chown -R` afterwards: chown rewrites every inode, so a later RUN
# would duplicate the whole tree — node_modules included — into an extra layer.
COPY --chown=node:node --from=builder /app/node_modules ./node_modules
COPY --chown=node:node --from=builder /opt/dsh /opt/dsh
COPY --chown=node:node --from=builder /opt/dsh-home /opt/dsh-home
# Second harness (add-harness-adapter D3): the ACP agent prefix + its PATH link.
COPY --chown=node:node --from=builder /opt/harness-acp /opt/harness-acp
# Browser lane (add-browser-use-lane): the prefix AND its env vars land HERE,
# never in the builder stage — an image whose runtime stage lacks them declares
# no lane and the image smoke honestly skips it (the 2026-10-28 first roll
# shipped exactly that: lane installed in builder, invisible in runtime). The
# system libraries ride install-deps in this stage's own layer.
COPY --chown=node:node --from=builder /opt/browser-mcp /opt/browser-mcp
RUN /opt/browser-mcp/node_modules/.bin/playwright install-deps chromium \
&& rm -rf /var/lib/apt/lists/*
ENV PATH="/opt/dsh/node_modules/.bin:/opt/harness-acp/node_modules/.bin:${PATH}" \
DSH_HOME="/opt/dsh-home" \
BROWSER_MCP_CLI="/opt/browser-mcp/node_modules/@playwright/mcp/cli.js" \
BROWSER_RUNTIME_PATH="/opt/browser-mcp/ms-playwright" \
PLAYWRIGHT_BROWSERS_PATH="/opt/browser-mcp/ms-playwright"
COPY --chown=node:node --from=builder /app/web/dist ./web/dist
# Facet service + its built thin SPA (same-image second role; see builder note).
# mcp-catalog.js is imported by facet/index.js (S2 registry 聚合读面); pairing.js
# mounts the device-pairing doors (F3.2 publish bridge); publish-gate.js is the
# same-name publish pre-route (add-mixed-fleet-packs 3.1); mcp-registry-json.js
# is the MCP Registry server.json projection (add-marketplace-projection-fanout)
# and credential-pattern.js is the credential shape it scans with — a facet
# import NOT on this list crashloops the facet role only (the platform-role
# smoke gate cannot catch it); supply-catalog.js is the unified supply catalog
# reader facet/index.js inits at boot (add-supply-catalog-unification W1);
# cli/ is deliberately NOT shipped — it is the
# npm-published @finddata/facet package, not part of the runtime. That last rule
# is why credential-pattern.js exists: marketplace-repo.js (the offline exporter,
# NOT shipped) imports facet/cli/, so the runtime needed the pattern without it.
COPY --chown=node:node --from=builder /app/facet/index.js /app/facet/identity.js /app/facet/mcp-catalog.js /app/facet/supply-catalog.js /app/facet/marketplace-json.js /app/facet/pairing.js /app/facet/publish-gate.js /app/facet/mcp-registry-json.js /app/facet/credential-pattern.js /app/facet/studio.js /app/facet/preview-sandbox.js /app/facet/machine-paths.js /app/facet/team-console-proxy.js /app/facet/fleets-db.js /app/facet/fleet-authority.js /app/facet/fleets-routes.js /app/facet/workbench-routes.js /app/facet/run-selections.js /app/facet/run-bridge-client.js /app/facet/plaza-export-schedule.js /app/facet/solution-routes.js ./facet/
COPY --chown=node:node --from=builder /app/facet/web/dist ./facet/web/dist
# Force-correct domains.json: Vite/buildx cache may serve a stale copy.
COPY --chown=node:node --from=builder /app/facet/web/public/domains.json ./facet/web/dist/domains.json
# Built-in packs: knowledge/memory/zhiyu manifests read at boot by
# refresh-builtin-pack-manifests-on-boot. Without this line the image boots
# fine (bootstrap catches ENOENT) but surfaces stays empty — same class of
# silent regression as the facet COPY line above.
COPY --chown=node:node --from=builder /app/packs ./packs
# 门厅静态物(unify-supply-spine-lineage D2):facet 进程启动时把它铺到
# FACET_SITE_ROOT,让根路径直接是素材广场而不是 SPA 介绍页。
# 只带页面资产——generated/(运行时导出产物)与 deploy/(部署手册,含雷池 IP)
# 不进镜像。
COPY --chown=node:node --from=builder /app/site-plaza/index.html /app/site-plaza/style.css /app/site-plaza/script.js /app/site-plaza/capability-domains.json /app/site-plaza/favicon.svg /app/site-plaza/og.png ./site-plaza/
COPY --chown=node:node --from=builder /app/site-plaza/locales ./site-plaza/locales
# Application source: all root .js (server.js, paths.js, local-services.js,
# bundle-manifest.js, chat-history.js, documents.js, mcp-bridge.js, …) + the
# root JSON data files read at runtime (market-catalog*.json;
# market-annotations.json — the repo annotation source, add-mcp-annotation-overlay
# D7: if this line is dropped the loader degrades to an empty table, so the
# image still boots and every entry renders raw upstream text;
# builtin-annotations.json — display labels for the platform's OWN MCP tools,
# same degradation: absent means the chat shows the raw callable name)
# + the dirs the supervisor/launcher need at runtime.
COPY --chown=node:node --from=builder /app/package.json /app/platform.bundle.json /app/mcp.example.json /app/agents.json ./
COPY --chown=node:node --from=builder /app/market-catalog.json /app/market-catalog-skills.json /app/market-starters.json /app/market-starters-skills.json /app/market-annotations.json /app/builtin-annotations.json ./
# The chart replay allowlist (openspec: add-chart-data-binding): read at boot by
# dsh-profile.js, which copies it into $DSH_HOME/profiles/<name> for the
# chart-bind bridge, and by chart-bindings.js as the replay gate. It is JSON, so
# `/app/*.js` below does not carry it — without this line the image boots and the
# feature works, but both allowlist readers silently fall back to their built-in
# default (observed on prod 2026-09-28: the plugin's gate was inert).
COPY --chown=node:node --from=builder /app/chart-replay-allowlist.json ./
# The frozen dsh install matrix (add-dsh-matrix-lock): the boot gate in
# server.js and agent-runner reads package-lock.json from here to verify
# /opt/dsh at startup. Missing lock + present install root would refuse to
# boot — so this COPY is load-bearing for the gate, not documentation.
COPY --chown=node:node --from=builder /app/dsh-matrix ./dsh-matrix
COPY --chown=node:node --from=builder /app/*.js ./
# Provenance beside the code it describes: `kubectl exec deploy/platform --
# cat /app/BUILD-INFO.json` answers "which base is this image?" without trusting
# the manifest comment (2026-11-08 shipped an image whose comment named a paas
# commit the tree did not contain).
COPY --chown=node:node --from=builder /app/BUILD-INFO.json ./
COPY --chown=node:node --from=builder /app/server ./server
# gateway/ is imported by server.js (the mini-program identity modules,
# add-single-process-mp-auth); /app/*.js does not descend into dirs, and a
# missing dir here boots the image just fine until its first import — the
# smoke test catches it as ERR_MODULE_NOT_FOUND.
COPY --chown=node:node --from=builder /app/gateway ./gateway
# packages/core is imported DIRECTLY by server-side modules: server/roles.js,
# server/layout.js and server/onboarding.js resolve the shared role / surface /
# recipe contracts from ../packages/core/src/lib/*.ts (Node strips the types at
# load). Without this dir the very first import throws ERR_MODULE_NOT_FOUND and
# every cell crashloops — the 2026-10-17 incident. Local runs never saw it
# because the repo tree has packages/ on disk; only the packaged image did.
COPY --chown=node:node --from=builder /app/packages ./packages
COPY --chown=node:node --from=builder /app/lib ./lib
COPY --chown=node:node --from=builder /app/scripts ./scripts
COPY --chown=node:node --from=builder /app/supervisor ./supervisor
COPY --chown=node:node --from=builder /app/bootstrap ./bootstrap
COPY --chown=node:node --from=builder /app/skills ./skills
# Canonical scoped-token implementation re-exported by lib/scoped-relay-token.js
# (add-mcp-credential-hygiene). Narrow copy on purpose: services/search-relay/
# also holds the gitignored keys.json with REAL credential material — that must
# never ride along into an image.
COPY --chown=node:node --from=builder /app/services/search-relay/scoped-token.js ./services/search-relay/scoped-token.js
# Read at RUNTIME by dsh-profile.js (it copies the two bridge plugins out of here
# into $DSH_HOME/profiles/<name>), so the builder copy above is not enough — an
# image without this dir boots, binds the port, then dies on ENOENT.
COPY --chown=node:node --from=builder /app/dsh-profile-template ./dsh-profile-template
# Same-image third role (fix-agent-data-workspace-writes): the agent-runner
# (`node agent-runner/index.js`, ADR-0004) rides this image with a different
# entrypoint. Without this COPY the image boots and the platform serves
# normally — only the runner role cannot start, which is how the runner
# deployment drifted into bind-mounted code + SFTP hotfixes. Its deps
# (dsh-sdk-client, express, js-yaml) are already in the root node_modules.
COPY --chown=node:node --from=builder /app/agent-runner ./agent-runner
# Office execution layer (add-doc-studio): pinned pure-python + wheel deps only
# (~60MB site-packages; markitdown deliberately absent — see requirements-office.txt).
# This layer sits AFTER the source COPYs on purpose: a requirements bump
# cache-busts only this layer, not the node_modules / dist layers above, and a
# source change does not re-run pip. aliyun pypi mirror pairs with the aliyun
# apt mirror above (China build host).
COPY --chown=node:node --from=builder /app/requirements-office.txt ./
RUN pip3 install --no-cache-dir --break-system-packages \
-i https://mirrors.aliyun.com/pypi/simple/ \
-r requirements-office.txt \
&& rm requirements-office.txt
# Persistent state lives under /data: SQLite, sessions, chat-history, cron,
# dev-settings.json. PLATFORM_DATA_DIR points the supervisor (local-services.js)
# + paths.js here. HOST=0.0.0.0 so k8s probes + docker port-forward reach
# server.js inside the container.
#
# DSH_BIN pins the agent runtime to the frozen matrix tree. dsh-bridge's
# resolution prefers the APP tree's node_modules/@deepseek-ai/dsh/lib/bin.js
# when present (the packaged-desktop case), but in this image the app tree is
# the two-generation root closure (rc.2 runtime + rc.5 server rows) whose
# hoisting split breaks that binary: @deepseek-ai/cordis-plugin-group sits at
# the app tree's top level with its peer cordis-plugin-loader only nested, so
# the nested dsh-app-boot's `import Group from "@deepseek-ai/cordis-plugin-
# group"` lands on the top-level copy and dies with ERR_MODULE_NOT_FOUND
# (2026-10-09 prod roll sha-f2af032: every cell's agent init failed — chat
# showed "No model"; reproduced locally with the same command). /opt/dsh is
# the tree the boot hard gate + dsh-contracts verify (6/6), so the image must
# spawn THAT one.
ENV NODE_ENV=production \
HOST=0.0.0.0 \
PORT=3000 \
PLATFORM_DATA_DIR=/data \
DSH_BIN=/opt/dsh/node_modules/@deepseek-ai/dsh/lib/bin.js
# Run as the image's non-root `node` user (UID/GID 1000 in the official node image).
# Only /data is writable at runtime (PLATFORM_DATA_DIR); the app tree already
# carries node ownership from the COPY --chown above, so there is no recursive
# chown here — see the note on those COPY lines.
# /data/workspace is the AGENT_WORKSPACE default target (fix-agent-workspace):
# produced files must land under the serving root or they can be neither
# previewed, downloaded, nor saved to resources. A deployment mounting /data
# from a hostPath masks this dir — its runbook step creates it on the host
# (operator's responsibility when /data is a host mount).
RUN mkdir -p /data/workspace && chown -R node:node /data
USER node
EXPOSE 3000
# No baked HEALTHCHECK: this image carries three roles (cell/facet on 3000,
# runner on 8790) and a role-specific probe mislabels the others unhealthy
# (one runner lived "unhealthy" for a generation). Each
# role defines its own: k8s roles use k8s probes; the runner's compose and the
# ops runbook carries the 8790 /health probe.
# start.js → local-services.js → Supervisor spawns server.js, then keeps running.
CMD ["node", "scripts/start.js"]