Sfoglia il codice sorgente

【更改,构建】镜像内置编译工具链与 Rust

agent 运行时装 dsh 插件(dsh-better-sidebar 等)触发 node-pty 现场编译
(prebuild 未匹配时回退 node-gyp),运行镜像瘦身时移除了工具链导致
gyp 报 not found: make。运行阶段恢复 make/gcc/g++/pkg-config 并新增
Rust(rustup stable minimal + rustfmt + clippy),RUSTUP_HOME/CARGO_HOME
置系统目录并 chown node,cargo/bin 软链至 /usr/local/bin 适配 agent
白名单 PATH;RUSTUP_DIST_SERVER 可经 build-arg 覆盖。
取舍:镜像体积回升 ~600MB,换取运行时 native 模块自编译能力。
PJ568 3 mesi fa
parent
commit
e900eba38a
5 ha cambiato i file con 65 aggiunte e 18 eliminazioni
  1. 1 0
      DESIGN.md
  2. 56 13
      Dockerfile
  3. 3 2
      README.md
  4. 3 2
      README.zh.md
  5. 2 1
      defaults/AGENTS.md

+ 1 - 0
DESIGN.md

@@ -221,4 +221,5 @@ docker compose up -d --build  # 或 docker compose up -d(用 GHCR 镜像时)
 | chown 属主修正 | 每次启动无条件 `chown -R node:node /home/node` | 仅当根目录属主非 1000:1000 时全量修正,否则跳过 | 数据卷含 x-cmd 工具(数万文件),全量递归拖慢每次重启 |
 | trustedHosts 注入条件 | 仅当 `cordis.patch.yml` 不存在时注入 | 不存在**或为空模板**(顶层数组 `[]`,即 dsh 首启生成)时注入;已有内容/不可解析时跳过并提示 | dsh 首启自动生成空模板 patch(initProfile 对已存在文件不覆盖),用户首启未设变量、后设变量重启需能自动注入;已维护的 patch 绝不覆盖 |
 | 镜像构建(单阶段) | 单阶段 npm install,build-essential 安装于独立 RUN、purge 在后续层 | 多阶段构建:builder 阶段(build-essential+python3)编译 native 依赖(node-pty/sharp),运行镜像仅 COPY node_modules 与 dsh 入口;bin 用 `RUN ln -s` 重建(docker COPY 单文件会解引用 symlink,导致 ESM 从 /usr/local/bin/dsh 解析依赖失败);COREPACK_HOME 移至 /usr/local/share/corepack 避免 root 缓存 | 镜像 1.6GB → 1.19GB(省 build-essential 层残留 ~250MB + /root/.cache 88MB);node-pty/sharp 动态依赖(libstdc++/libgcc_s/glibc)由 node:22-slim 自带,运行阶段无需工具链 |
+| 运行阶段工具链 | 运行镜像不含编译工具链(瘦身) | 运行镜像恢复轻量编译工具链(make/gcc/g++/pkg-config)+ Rust(rustup stable minimal + rustfmt + clippy) | agent 运行时装 dsh 插件(dsh-better-sidebar 等)触发 node-pty 现场编译(prebuild 未匹配时回退 node-gyp),缺 make 直接报 `not found: make`;Rust 供 agent `cargo build` 编译项目。RUSTUP_HOME/CARGO_HOME 置系统目录并 chown node,cargo/bin 软链至 /usr/local/bin(agent PATH 白名单固定)。取舍:镜像体积回升(+~600MB),换取运行时 native 模块自编译能力,避免每次插件安装都需重建镜像 |
 

+ 56 - 13
Dockerfile

@@ -11,11 +11,14 @@
 #
 # Build: docker build --build-arg DSH_VERSION=0.1.0-rc.7 -t dsh-web:latest .
 #
-# 多阶段:builder 阶段含编译工具链(node-pty/sharp 等 native 依赖),
-# 运行镜像只 COPY 编译产物,不含 gcc/make/python-dev 痕迹
+# 多阶段:builder 阶段编译 dsh(node-pty/sharp 等 native 依赖),
+# 运行镜像 COPY 编译产物,并保留轻量编译工具链 + Rust:agent 运行时装 native
+# 模块(dsh 插件 node-pty 等)需现场编译兜底;详见运行阶段注释
 #
-# Multi-stage: the builder stage holds the toolchain for native deps (node-pty/sharp);
-# the runtime image only copies compiled artifacts, with no gcc/make/python-dev remnants
+# Multi-stage: the builder stage compiles dsh (native deps such as node-pty/sharp);
+# the runtime image copies compiled artifacts AND keeps a lightweight toolchain + Rust,
+# so agents can compile native modules (e.g. plugin node-pty) at runtime as a fallback.
+# See the runtime stage notes for the trade-off.
 
 ARG DSH_VERSION=0.1.0-rc.7
 
@@ -35,9 +38,12 @@ ARG DSH_VERSION
 
 ENV DEBIAN_FRONTEND=noninteractive
 
-# build-essential + python3 仅用于 npm 编译,本阶段镜像不产出到运行镜像
+# build-essential + python3 仅用于本阶段编译 dsh 自带的 native 依赖(node-pty/sharp);
+# 运行镜像另装轻量工具链(make/gcc/g++)供 agent 现场编译插件 native 依赖,见运行阶段
 #
-# build-essential + python3 are only for npm compilation; this stage's image never reaches the runtime
+# build-essential + python3 are only for compiling dsh's bundled native deps (node-pty/sharp) in this stage;
+# the runtime image installs a lightweight toolchain (make/gcc/g++) separately for agents to compile
+# plugin native deps on site — see the runtime stage
 # hadolint ignore=DL3008
 RUN apt-get update \
  && apt-get install -y --no-install-recommends build-essential python3 \
@@ -60,22 +66,32 @@ ENV DEBIAN_FRONTEND=noninteractive
 COPY --from=caddy /usr/bin/caddy /usr/bin/caddy
 
 # dsh 编译产物:node_modules(含 node-pty/sharp native 二进制)与 dsh 入口
-# 动态依赖 libstdc++/libgcc_s/glibc 由 node:22-slim 自带,运行无需编译工具链
+# 动态依赖 libstdc++/libgcc_s/glibc 由 node:22-slim 自带,dsh 核心运行无需工具链;
+# 但 agent 运行时装插件(dsh-better-sidebar 等)会触发 node-pty 现场编译
+# (prebuild 未匹配时回退 node-gyp),故运行阶段另装 make/gcc/g++(见下)
 # bin 用 RUN ln -s 重建:COPY 单文件会解引用 symlink,导致 ESM 从 /usr/local/bin/dsh
 # 解析依赖失败(node_modules 不可达)
 #
-# dsh compiled artifacts: node_modules (with node-pty/sharp native binaries) and the dsh entry
-# Dynamic deps (libstdc++/libgcc_s/glibc) ship with node:22-slim; no toolchain is needed at runtime
+# dsh compiled artifacts: node_modules (with node-pty/sharp native binaries) and the dsh entry.
+# Dynamic deps (libstdc++/libgcc_s/glibc) ship with node:22-slim, so dsh core needs no toolchain;
+# however, agents installing plugins at runtime (e.g. dsh-better-sidebar) trigger on-site node-pty
+# compilation (node-gyp fallback when no prebuild matches), hence make/gcc/g++ in the runtime stage.
 # The bin is rebuilt with RUN ln -s: COPY of a single file dereferences the symlink, breaking
-# ESM resolution from /usr/local/bin/dsh (node_modules unreachable)
+# ESM resolution from /usr/local/bin/dsh (node_modules unreachable).
 COPY --from=builder /usr/local/lib/node_modules /usr/local/lib/node_modules
 RUN ln -s ../lib/node_modules/@deepseek-ai/dsh/lib/bin.js /usr/local/bin/dsh
 
 # 运行依赖与 agent 工具集
-# 全部可在白名单 bash 环境直接调用;无 build-essential(编译只在 builder 阶段)
+# 全部可在白名单 bash 环境直接调用(PATH 固定 /usr/local/sbin:/usr/local/bin:/usr/bin)
+# 轻量编译工具链(make/gcc/g++/pkg-config):agent 运行时装 dsh 插件触发 native 模块
+# 现场编译(node-pty prebuild 未匹配时回退 node-gyp),缺 make 会直接报错;不装完整
+# build-essential 以控制体积(省 dpkg-dev/gdb 等)
 #
 # Runtime Dependencies and Agent Toolset
-# All directly callable in the whitelisted bash environment; no build-essential (compilation stays in the builder stage)
+# All directly callable in the whitelisted bash environment (PATH fixed to /usr/local/sbin:/usr/local/bin:/usr/bin).
+# Lightweight toolchain (make/gcc/g++/pkg-config): agents installing dsh plugins trigger on-site native
+# module compilation (node-gyp fallback when node-pty prebuild doesn't match); a missing make fails hard.
+# Full build-essential is avoided to keep the image slim (drops dpkg-dev/gdb etc.).
 #
 # - supervisor(PID 1 进程管理,Python 包,python3 保留)
 # - git/openssh-client:git 工作流(GIT_PAGER=cat 表明 dsh 预期 git 存在)
@@ -83,13 +99,14 @@ RUN ln -s ../lib/node_modules/@deepseek-ai/dsh/lib/bin.js /usr/local/bin/dsh
 # - procps(ps/kill/pgrep):进程排查;ripgrep:代码搜索;rsync:同步
 # - yq:YAML 处理;file:类型识别;dnsutils(dig):DNS 排查;sqlite3:数据
 # - python3-pip:python 包管理(pip install --user);vim-tiny:vi 编辑器兜底
+# - make/gcc/g++/pkg-config:node-gyp 编译 native 模块(node-pty 等)兜底
 #
 # 有意不 pin apt 版本:依赖 Debian 源自动更新;npm 版本已由 ARG DSH_VERSION pin
 #
 # Apt versions are deliberately unpinned: Debian sources auto-update; npm is pinned by ARG DSH_VERSION
 # hadolint ignore=DL3008
 RUN apt-get update \
- && apt-get install -y --no-install-recommends supervisor ca-certificates git openssh-client curl wget jq unzip zip procps ripgrep rsync yq file dnsutils sqlite3 python3-pip vim-tiny python3 \
+ && apt-get install -y --no-install-recommends supervisor ca-certificates git openssh-client curl wget jq unzip zip procps ripgrep rsync yq file dnsutils sqlite3 python3-pip vim-tiny python3 make gcc g++ pkg-config \
  && rm -rf /var/lib/apt/lists/*
 
 # pnpm
@@ -104,6 +121,32 @@ RUN corepack enable \
  && corepack prepare pnpm@10 --activate \
  && rm -rf /root/.cache
 
+# Rust 工具链(rustup 官方方式,minimal profile + rustfmt/clippy)
+# agent 运行时可直接 cargo build/rustc 编译项目;profile minimal 不含 rust-docs 以控制体积
+# RUSTUP_HOME/CARGO_HOME 指向系统目录并 chown 给 node:agent 无 root 也能 rustup component add
+# agent 的 bash PATH 白名单固定(/usr/local/sbin:/usr/local/bin:/usr/bin),故把 cargo/bin 下
+# 可执行文件软链到 /usr/local/bin(与 x-cmd shim 同一接入点策略)
+# RUSTUP_DIST_SERVER 可经 build-arg 覆盖(国内构建若 static.rust-lang.org 不可达可设 rsproxy.cn)
+#
+# Rust toolchain (official rustup, minimal profile + rustfmt/clippy)
+# Agents can cargo build/rustc directly at runtime; minimal profile omits rust-docs to save space.
+# RUSTUP_HOME/CARGO_HOME point to system dirs and are chowned to node, so non-root agents can
+# `rustup component add` too. The agent's bash PATH is a fixed whitelist
+# (/usr/local/sbin:/usr/local/bin:/usr/bin), so cargo/bin executables are symlinked into
+# /usr/local/bin (same entry-point strategy as the x-cmd shims).
+# RUSTUP_DIST_SERVER can be overridden via build-arg (set to rsproxy.cn if static.rust-lang.org
+# is unreachable in your build environment).
+ENV RUSTUP_HOME=/usr/local/rustup \
+    CARGO_HOME=/usr/local/cargo
+ARG RUSTUP_DIST_SERVER=https://static.rust-lang.org
+RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
+      | sh -s -- -y --profile minimal --default-toolchain stable --no-modify-path \
+                 --component rustfmt --component clippy \
+ && find /usr/local/cargo/bin -maxdepth 1 -type f -executable \
+      -exec ln -sf {} /usr/local/bin/ \; \
+ && chown -R node:node /usr/local/rustup /usr/local/cargo \
+ && rm -rf /usr/local/rustup/tmp/* /usr/local/cargo/registry/cache
+
 # 运行用户与数据目录
 # 非 root 运行用户:复用官方镜像自带的 node 用户(uid 1000,home /home/node)
 # 数据目录 /home/node/.dsh 挂载卷;uid 1000 便于宿主机 bind mount 属主对齐

+ 3 - 2
README.md

@@ -77,6 +77,7 @@ dsh agents run commands inside the container through the bash tool; the availabl
 ### Preinstalled in the image
 
 - Runtime: node 22, npm, pnpm (corepack, required by `dsh plugin`), python3, Caddy, dsh
+- Build toolchain: make/gcc/g++/pkg-config (node-gyp fallback for native modules, e.g. a dsh plugin's node-pty), Rust (rustup stable minimal + rustfmt + clippy)
 - Agent tools: git, openssh-client, curl/wget (network), jq/yq (JSON/YAML), ripgrep (search), rsync (sync), procps (processes), zip/unzip/tar, file, dig, sqlite3, python3-pip, vim-tiny, ca-certificates
 
 ### Agent self-installation (x-cmd, no root required)
@@ -101,11 +102,11 @@ jq . data.json                # bare command: enabled packages are symlinked to
 For the in-container agent environment guide, see `AGENTS.md` in the data volume (auto-loaded by dsh sessions).
 
 
-System packages that require root (build toolchain like gcc/make, editors, etc.): modify the `apt-get install` line in the `Dockerfile` and rebuild, or add a layer on top of this image:
+The image already ships a lightweight build toolchain (make/gcc/g++) and Rust, so agents can run `pnpm install`/`cargo build` to compile native modules and projects directly. Other system packages that require root can be added by modifying the `apt-get install` line in the `Dockerfile` and rebuilding, or by adding a layer on top of this image:
 
 ```dockerfile
 FROM ghcr.io/xidong-ai/deepseek-harness-web-docker:latest
-RUN apt-get update && apt-get install -y --no-install-recommends build-essential \
+RUN apt-get update && apt-get install -y --no-install-recommends <pkg> \
  && rm -rf /var/lib/apt/lists/*
 ```
 

+ 3 - 2
README.zh.md

@@ -77,6 +77,7 @@ dsh 的 agent 通过 bash 工具在容器内执行命令,可用工具集 = 镜
 ### 镜像预装
 
 - 运行时:node 22、npm、pnpm(corepack,`dsh plugin` 依赖)、python3、Caddy、dsh
+- 编译工具链:make/gcc/g++/pkg-config(node-gyp 编译 native 模块兜底,如 dsh 插件的 node-pty)、Rust(rustup stable minimal + rustfmt + clippy)
 - agent 工具:git、openssh-client、curl/wget(网络)、jq/yq(JSON/YAML)、ripgrep(搜索)、rsync(同步)、procps(进程)、zip/unzip/tar、file、dig、sqlite3、python3-pip、vim-tiny、ca-certificates
 
 ### agent 自行安装(x-cmd,免 root)
@@ -101,11 +102,11 @@ jq . data.json                # 裸命令:已启用包已软链至 /usr/local/
 容器内 agent 的环境指引见数据卷 `AGENTS.md`(dsh 会话自动加载)。
 
 
-编译工具链(gcc/make)、编辑器等需 root 的系统包,修改 `Dockerfile` 的 `apt-get install` 行重建,或基于本镜像追加一层:
+镜像已内置轻量编译工具链(make/gcc/g++)与 Rust,agent 可直接 `pnpm install`/`cargo build` 编译 native 模块与项目。仍缺的其他系统包需 root 安装,可修改 `Dockerfile` 的 `apt-get install` 行重建,或基于本镜像追加一层:
 
 ```dockerfile
 FROM ghcr.io/xidong-ai/deepseek-harness-web-docker:latest
-RUN apt-get update && apt-get install -y --no-install-recommends build-essential \
+RUN apt-get update && apt-get install -y --no-install-recommends <pkg> \
  && rm -rf /var/lib/apt/lists/*
 ```
 

+ 2 - 1
defaults/AGENTS.md

@@ -5,6 +5,7 @@
 ## 预装工具
 
 - 运行时:node 22、npm、pnpm(corepack)、python3、Caddy
+- 编译工具链:make/gcc/g++/pkg-config(node-gyp 编译 native 模块兜底,如 dsh 插件的 node-pty)、Rust(rustup stable minimal + rustfmt + clippy,`cargo build`/`rustc` 直接可用)
 - 常用工具:git、openssh-client、curl、wget、jq、yq、ripgrep、rsync、ps/pgrep、zip/unzip/tar、file、dig、sqlite3、pip、vim-tiny
 
 ## 自行安装工具(x-cmd,免 root)
@@ -29,6 +30,6 @@ x env which <pkg>         # 查看路径
 
 ## 限制
 
-- 无 root/apt 权限,不能安装系统级包(gcc/make 等需自定义镜像,[见项目 README](https://github.com/Xidong-AI/deepseek-harness-web-docker/raw/refs/heads/master/README.zh.md));
+- 无 root/apt 权限,不能安装系统级包;但编译工具链(make/gcc/g++)与 Rust 已预装,可直接 `pnpm install`/`cargo build` 编译 native 模块与项目。其余系统包需自定义镜像,[见项目 README](https://github.com/Xidong-AI/deepseek-harness-web-docker/raw/refs/heads/master/README.zh.md);
 - 不读 shell rc 文件:每次 bash -c 为全新环境,PATH 固定(/usr/local/sbin:/usr/local/bin:/usr/bin);
 - 文件沙箱:工作区之外的文件操作可能被拒绝(见工具描述)——包括 x-cmd 对 `~/.x-cmd.root` 的写入,沙箱下需完整权限才能用 `x`。