Dockerfile 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. # syntax=docker/dockerfile:1
  2. # DeepSeek Harness Web Docker 镜像
  3. #
  4. # DeepSeek Harness Web Docker image
  5. #
  6. # 单容器:dsh(127.0.0.1:3080) + Caddy basic auth(0.0.0.0:3081),supervisord 管理
  7. #
  8. # Single container: dsh (127.0.0.1:3080) + Caddy basic auth (0.0.0.0:3081), managed by supervisord
  9. #
  10. # 构建:docker build --build-arg DSH_VERSION=0.1.1-rc.2 -t dsh-web:latest .
  11. #
  12. # Build: docker build --build-arg DSH_VERSION=0.1.1-rc.2 -t dsh-web:latest .
  13. #
  14. # 多阶段:builder 阶段编译 dsh(node-pty/sharp 等 native 依赖),
  15. # 运行镜像 COPY 编译产物,并保留轻量编译工具链 + Rust:agent 运行时装 native
  16. # 模块(dsh 插件 node-pty 等)需现场编译兜底;详见运行阶段注释
  17. #
  18. # Multi-stage: the builder stage compiles dsh (native deps such as node-pty/sharp);
  19. # the runtime image copies compiled artifacts AND keeps a lightweight toolchain + Rust,
  20. # so agents can compile native modules (e.g. plugin node-pty) at runtime as a fallback.
  21. # See the runtime stage notes for the trade-off.
  22. ARG DSH_VERSION=0.2.2-rc.5
  23. # Caddy 官方镜像
  24. # 静态二进制,与平台无关
  25. #
  26. # Caddy Official Image
  27. # Static binary, platform-independent
  28. FROM caddy:2-alpine AS caddy
  29. # ---- builder 阶段:编译 dsh(node-pty / sharp 等 native 依赖)----
  30. #
  31. # ---- builder stage: compile dsh (native deps such as node-pty / sharp) ----
  32. FROM node:22-slim AS builder
  33. ARG DSH_VERSION
  34. ENV DEBIAN_FRONTEND=noninteractive
  35. # build-essential + python3 仅用于本阶段编译 dsh 自带的 native 依赖(node-pty/sharp);
  36. # 运行镜像另装轻量工具链(make/gcc/g++)供 agent 现场编译插件 native 依赖,见运行阶段
  37. #
  38. # build-essential + python3 are only for compiling dsh's bundled native deps (node-pty/sharp) in this stage;
  39. # the runtime image installs a lightweight toolchain (make/gcc/g++) separately for agents to compile
  40. # plugin native deps on site — see the runtime stage
  41. # hadolint ignore=DL3008
  42. RUN apt-get update \
  43. && apt-get install -y --no-install-recommends build-essential python3 \
  44. && npm install -g @deepseek-ai/dsh@${DSH_VERSION} \
  45. && npm cache clean --force \
  46. && rm -rf /var/lib/apt/lists/* /root/.npm /root/.cache
  47. # ---- 运行阶段 ----
  48. #
  49. # ---- runtime stage ----
  50. FROM node:22-slim
  51. ENV DEBIAN_FRONTEND=noninteractive
  52. # Caddy 静态二进制
  53. # 来自官方镜像,可在 glibc Debian 上直接运行
  54. #
  55. # Caddy Static Binary
  56. # From the official image, runs directly on glibc Debian
  57. COPY --from=caddy /usr/bin/caddy /usr/bin/caddy
  58. # dsh 编译产物:node_modules(含 node-pty/sharp native 二进制)与 dsh 入口
  59. # 动态依赖 libstdc++/libgcc_s/glibc 由 node:22-slim 自带,dsh 核心运行无需工具链;
  60. # 但 agent 运行时装插件(dsh-better-sidebar 等)会触发 node-pty 现场编译
  61. # (prebuild 未匹配时回退 node-gyp),故运行阶段另装 make/gcc/g++(见下)
  62. # bin 用 RUN ln -s 重建:COPY 单文件会解引用 symlink,导致 ESM 从 /usr/local/bin/dsh
  63. # 解析依赖失败(node_modules 不可达)
  64. #
  65. # dsh compiled artifacts: node_modules (with node-pty/sharp native binaries) and the dsh entry.
  66. # Dynamic deps (libstdc++/libgcc_s/glibc) ship with node:22-slim, so dsh core needs no toolchain;
  67. # however, agents installing plugins at runtime (e.g. dsh-better-sidebar) trigger on-site node-pty
  68. # compilation (node-gyp fallback when no prebuild matches), hence make/gcc/g++ in the runtime stage.
  69. # The bin is rebuilt with RUN ln -s: COPY of a single file dereferences the symlink, breaking
  70. # ESM resolution from /usr/local/bin/dsh (node_modules unreachable).
  71. COPY --from=builder /usr/local/lib/node_modules /usr/local/lib/node_modules
  72. RUN ln -s ../lib/node_modules/@deepseek-ai/dsh/lib/bin.js /usr/local/bin/dsh
  73. # 运行依赖与 agent 工具集
  74. # 全部可在白名单 bash 环境直接调用(PATH 固定 /usr/local/sbin:/usr/local/bin:/usr/bin)
  75. # 轻量编译工具链(make/gcc/g++/pkg-config):agent 运行时装 dsh 插件触发 native 模块
  76. # 现场编译(node-pty prebuild 未匹配时回退 node-gyp),缺 make 会直接报错;不装完整
  77. # build-essential 以控制体积(省 dpkg-dev/gdb 等)
  78. #
  79. # Runtime Dependencies and Agent Toolset
  80. # All directly callable in the whitelisted bash environment (PATH fixed to /usr/local/sbin:/usr/local/bin:/usr/bin).
  81. # Lightweight toolchain (make/gcc/g++/pkg-config): agents installing dsh plugins trigger on-site native
  82. # module compilation (node-gyp fallback when node-pty prebuild doesn't match); a missing make fails hard.
  83. # Full build-essential is avoided to keep the image slim (drops dpkg-dev/gdb etc.).
  84. #
  85. # - supervisor(PID 1 进程管理,Python 包,python3 保留)
  86. # - git/openssh-client:git 工作流(GIT_PAGER=cat 表明 dsh 预期 git 存在)
  87. # - curl/wget:网络下载;jq:JSON;unzip/zip:解压/压缩;tar(coreutils)
  88. # - procps(ps/kill/pgrep):进程排查;ripgrep:代码搜索;rsync:同步
  89. # - yq:YAML 处理;file:类型识别;dnsutils(dig):DNS 排查;sqlite3:数据
  90. # - python3-pip:python 包管理(pip install --user);vim-tiny:vi 编辑器兜底
  91. # - make/gcc/g++/pkg-config:node-gyp 编译 native 模块(node-pty 等)兜底
  92. #
  93. # 有意不 pin apt 版本:依赖 Debian 源自动更新;npm 版本已由 ARG DSH_VERSION pin
  94. #
  95. # Apt versions are deliberately unpinned: Debian sources auto-update; npm is pinned by ARG DSH_VERSION
  96. # hadolint ignore=DL3008
  97. RUN apt-get update \
  98. && 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 \
  99. && rm -rf /var/lib/apt/lists/*
  100. # pnpm
  101. # dsh plugin 命令在 profile 目录内转发给 pnpm(corepack 官方方式,pin 大版本)
  102. # COREPACK_HOME 指向系统目录:缓存不落在 /root,运行阶段可读且镜像不留 root 缓存
  103. #
  104. # pnpm
  105. # dsh plugin commands forward to pnpm inside the profile dir (official corepack way, major version pinned)
  106. # COREPACK_HOME points to a system dir so the cache never lands in /root (readable at runtime, no root cache in the image)
  107. ENV COREPACK_HOME=/usr/local/share/corepack
  108. RUN corepack enable \
  109. && corepack prepare pnpm@10 --activate \
  110. && rm -rf /root/.cache
  111. # Rust 工具链(rustup 官方方式,minimal profile + rustfmt/clippy)
  112. # agent 运行时可直接 cargo build/rustc 编译项目;profile minimal 不含 rust-docs 以控制体积
  113. # RUSTUP_HOME/CARGO_HOME 指向系统目录并 chown 给 node:agent 无 root 也能 rustup component add
  114. # agent 的 bash PATH 白名单固定(/usr/local/sbin:/usr/local/bin:/usr/bin),故把 cargo/bin 下
  115. # 可执行文件软链到 /usr/local/bin(与 x-cmd shim 同一接入点策略)
  116. # RUSTUP_DIST_SERVER 可经 build-arg 覆盖(国内构建若 static.rust-lang.org 不可达可设 rsproxy.cn)
  117. #
  118. # Rust toolchain (official rustup, minimal profile + rustfmt/clippy)
  119. # Agents can cargo build/rustc directly at runtime; minimal profile omits rust-docs to save space.
  120. # RUSTUP_HOME/CARGO_HOME point to system dirs and are chowned to node, so non-root agents can
  121. # `rustup component add` too. The agent's bash PATH is a fixed whitelist
  122. # (/usr/local/sbin:/usr/local/bin:/usr/bin), so cargo/bin executables are symlinked into
  123. # /usr/local/bin (same entry-point strategy as the x-cmd shims).
  124. # RUSTUP_DIST_SERVER can be overridden via build-arg (set to rsproxy.cn if static.rust-lang.org
  125. # is unreachable in your build environment).
  126. ENV RUSTUP_HOME=/usr/local/rustup \
  127. CARGO_HOME=/usr/local/cargo
  128. ARG RUSTUP_DIST_SERVER=https://static.rust-lang.org
  129. RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
  130. | sh -s -- -y --profile minimal --default-toolchain stable --no-modify-path \
  131. --component rustfmt --component clippy \
  132. && find /usr/local/cargo/bin -maxdepth 1 -type f -executable \
  133. -exec ln -sf {} /usr/local/bin/ \; \
  134. && chown -R node:node /usr/local/rustup /usr/local/cargo \
  135. && rm -rf /usr/local/rustup/tmp/* /usr/local/cargo/registry/cache
  136. # 运行用户与数据目录
  137. # 非 root 运行用户:复用官方镜像自带的 node 用户(uid 1000,home /home/node)
  138. # 数据目录 /home/node/.dsh 挂载卷;uid 1000 便于宿主机 bind mount 属主对齐
  139. #
  140. # Runtime User and Data Directory
  141. # Non-root runtime user: reuse the node user from the official image (uid 1000, home /home/node)
  142. # Data dir /home/node/.dsh is a mounted volume; uid 1000 aligns ownership for host bind mounts
  143. # 配置与入口
  144. #
  145. # Configuration and Entrypoint
  146. COPY defaults/ /opt/dsh/defaults/
  147. COPY Caddyfile /etc/caddy/Caddyfile
  148. COPY supervisord.conf /etc/supervisor/conf.d/dsh.conf
  149. COPY entrypoint.sh /usr/local/bin/entrypoint.sh
  150. # 构建收尾说明
  151. # Caddyfile 需 node 用户可读(COPY 保留源 600 权限)
  152. # vim-tiny 默认不注册 vim 命令名,补 alternatives 注册(vi 已自动可用)
  153. #
  154. # Build Finalization Notes
  155. # Caddyfile must be readable by the node user (COPY keeps the source 600 permission)
  156. # vim-tiny does not register the vim command by default; alternatives registration added (vi already available)
  157. RUN chmod 644 /etc/caddy/Caddyfile \
  158. && chmod +x /usr/local/bin/entrypoint.sh \
  159. && update-alternatives --install /usr/bin/vim vim /usr/bin/vim.tiny 10
  160. ENV HOME=/home/node
  161. EXPOSE 3081
  162. ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]