Dockerfile 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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.0-rc.7 -t dsh-web:latest .
  11. #
  12. # Build: docker build --build-arg DSH_VERSION=0.1.0-rc.7 -t dsh-web:latest .
  13. #
  14. # 多阶段:builder 阶段含编译工具链(node-pty/sharp 等 native 依赖),
  15. # 运行镜像只 COPY 编译产物,不含 gcc/make/python-dev 痕迹
  16. #
  17. # Multi-stage: the builder stage holds the toolchain for native deps (node-pty/sharp);
  18. # the runtime image only copies compiled artifacts, with no gcc/make/python-dev remnants
  19. ARG DSH_VERSION=0.1.0-rc.7
  20. # Caddy 官方镜像
  21. # 静态二进制,与平台无关
  22. #
  23. # Caddy Official Image
  24. # Static binary, platform-independent
  25. FROM caddy:2-alpine AS caddy
  26. # ---- builder 阶段:编译 dsh(node-pty / sharp 等 native 依赖)----
  27. #
  28. # ---- builder stage: compile dsh (native deps such as node-pty / sharp) ----
  29. FROM node:22-slim AS builder
  30. ARG DSH_VERSION
  31. ENV DEBIAN_FRONTEND=noninteractive
  32. # build-essential + python3 仅用于 npm 编译,本阶段镜像不产出到运行镜像
  33. #
  34. # build-essential + python3 are only for npm compilation; this stage's image never reaches the runtime
  35. # hadolint ignore=DL3008
  36. RUN apt-get update \
  37. && apt-get install -y --no-install-recommends build-essential python3 \
  38. && npm install -g @deepseek-ai/dsh@${DSH_VERSION} \
  39. && npm cache clean --force \
  40. && rm -rf /var/lib/apt/lists/* /root/.npm /root/.cache
  41. # ---- 运行阶段 ----
  42. #
  43. # ---- runtime stage ----
  44. FROM node:22-slim
  45. ENV DEBIAN_FRONTEND=noninteractive
  46. # Caddy 静态二进制
  47. # 来自官方镜像,可在 glibc Debian 上直接运行
  48. #
  49. # Caddy Static Binary
  50. # From the official image, runs directly on glibc Debian
  51. COPY --from=caddy /usr/bin/caddy /usr/bin/caddy
  52. # dsh 编译产物:node_modules(含 node-pty/sharp native 二进制)与 dsh 入口
  53. # 动态依赖 libstdc++/libgcc_s/glibc 由 node:22-slim 自带,运行无需编译工具链
  54. # bin 用 RUN ln -s 重建:COPY 单文件会解引用 symlink,导致 ESM 从 /usr/local/bin/dsh
  55. # 解析依赖失败(node_modules 不可达)
  56. #
  57. # dsh compiled artifacts: node_modules (with node-pty/sharp native binaries) and the dsh entry
  58. # Dynamic deps (libstdc++/libgcc_s/glibc) ship with node:22-slim; no toolchain is needed at runtime
  59. # The bin is rebuilt with RUN ln -s: COPY of a single file dereferences the symlink, breaking
  60. # ESM resolution from /usr/local/bin/dsh (node_modules unreachable)
  61. COPY --from=builder /usr/local/lib/node_modules /usr/local/lib/node_modules
  62. RUN ln -s ../lib/node_modules/@deepseek-ai/dsh/lib/bin.js /usr/local/bin/dsh
  63. # 运行依赖与 agent 工具集
  64. # 全部可在白名单 bash 环境直接调用;无 build-essential(编译只在 builder 阶段)
  65. #
  66. # Runtime Dependencies and Agent Toolset
  67. # All directly callable in the whitelisted bash environment; no build-essential (compilation stays in the builder stage)
  68. #
  69. # - supervisor(PID 1 进程管理,Python 包,python3 保留)
  70. # - git/openssh-client:git 工作流(GIT_PAGER=cat 表明 dsh 预期 git 存在)
  71. # - curl/wget:网络下载;jq:JSON;unzip/zip:解压/压缩;tar(coreutils)
  72. # - procps(ps/kill/pgrep):进程排查;ripgrep:代码搜索;rsync:同步
  73. # - yq:YAML 处理;file:类型识别;dnsutils(dig):DNS 排查;sqlite3:数据
  74. # - python3-pip:python 包管理(pip install --user);vim-tiny:vi 编辑器兜底
  75. #
  76. # 有意不 pin apt 版本:依赖 Debian 源自动更新;npm 版本已由 ARG DSH_VERSION pin
  77. #
  78. # Apt versions are deliberately unpinned: Debian sources auto-update; npm is pinned by ARG DSH_VERSION
  79. # hadolint ignore=DL3008
  80. RUN apt-get update \
  81. && 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 \
  82. && rm -rf /var/lib/apt/lists/*
  83. # pnpm
  84. # dsh plugin 命令在 profile 目录内转发给 pnpm(corepack 官方方式,pin 大版本)
  85. # COREPACK_HOME 指向系统目录:缓存不落在 /root,运行阶段可读且镜像不留 root 缓存
  86. #
  87. # pnpm
  88. # dsh plugin commands forward to pnpm inside the profile dir (official corepack way, major version pinned)
  89. # COREPACK_HOME points to a system dir so the cache never lands in /root (readable at runtime, no root cache in the image)
  90. ENV COREPACK_HOME=/usr/local/share/corepack
  91. RUN corepack enable \
  92. && corepack prepare pnpm@10 --activate \
  93. && rm -rf /root/.cache
  94. # 运行用户与数据目录
  95. # 非 root 运行用户:复用官方镜像自带的 node 用户(uid 1000,home /home/node)
  96. # 数据目录 /home/node/.dsh 挂载卷;uid 1000 便于宿主机 bind mount 属主对齐
  97. #
  98. # Runtime User and Data Directory
  99. # Non-root runtime user: reuse the node user from the official image (uid 1000, home /home/node)
  100. # Data dir /home/node/.dsh is a mounted volume; uid 1000 aligns ownership for host bind mounts
  101. # 配置与入口
  102. #
  103. # Configuration and Entrypoint
  104. COPY defaults/ /opt/dsh/defaults/
  105. COPY Caddyfile /etc/caddy/Caddyfile
  106. COPY supervisord.conf /etc/supervisor/conf.d/dsh.conf
  107. COPY entrypoint.sh /usr/local/bin/entrypoint.sh
  108. # 构建收尾说明
  109. # Caddyfile 需 node 用户可读(COPY 保留源 600 权限)
  110. # vim-tiny 默认不注册 vim 命令名,补 alternatives 注册(vi 已自动可用)
  111. #
  112. # Build Finalization Notes
  113. # Caddyfile must be readable by the node user (COPY keeps the source 600 permission)
  114. # vim-tiny does not register the vim command by default; alternatives registration added (vi already available)
  115. RUN chmod 644 /etc/caddy/Caddyfile \
  116. && chmod +x /usr/local/bin/entrypoint.sh \
  117. && update-alternatives --install /usr/bin/vim vim /usr/bin/vim.tiny 10
  118. ENV HOME=/home/node
  119. EXPOSE 3081
  120. ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]