yun tianming commited on
Commit
4e6ee18
·
verified ·
1 Parent(s): 1c08a8d

Upload 5 files

Browse files
Files changed (3) hide show
  1. Dockerfile +48 -26
  2. config/config.yaml +6 -0
  3. src/data_sync.py +8 -0
Dockerfile CHANGED
@@ -2,72 +2,94 @@ FROM python:3.11-slim
2
 
3
  LABEL maintainer="Hermes Agent Community"
4
  LABEL version="0.10.0"
5
- LABEL description="Hermes Agent v0.10.0 on Hugging Face Spaces with persistent storage and model config protection"
6
 
7
- # 设置环境变量
8
  ENV PYTHONUNBUFFERED=1
9
  ENV DEBIAN_FRONTEND=noninteractive
10
  ENV HERMES_HOME=/data/.hermes
11
  ENV PYTHONPATH=/app
12
 
13
- # 安装系统依赖
 
 
 
 
 
 
14
  RUN apt-get update && apt-get install -y \
15
  build-essential \
16
- nodejs \
17
- npm \
18
  ffmpeg \
19
  git \
20
  curl \
21
  unzip \
 
22
  && rm -rf /var/lib/apt/lists/*
23
 
24
- # 安装 yq (YAML 处理工具,用于运行时修改 config.yaml)
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  RUN curl -sL https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -o /usr/bin/yq && \
26
  chmod +x /usr/bin/yq
27
 
28
- # 安装 Python 依赖
29
  COPY requirements.txt /tmp/
30
  RUN pip install --no-cache-dir -r /tmp/requirements.txt
31
 
32
- # 克隆 Hermes Agent 仓库并本地构建前端(使用最新版本)
33
- # 移除 --branch 参数以始终获取最新代码,配合 --no-cache 确保每次都重新克隆
34
  RUN git clone --depth 1 https://github.com/NousResearch/hermes-agent.git /tmp/hermes-agent && \
35
- cd /tmp/hermes-agent/web && \
36
- npm install && \
37
- npm run build
38
-
39
- # 从本地路径安装 Hermes Agent [web] 包含 Dashboard 依赖
40
- RUN pip install --no-cache-dir /tmp/hermes-agent[all,web]
41
 
42
- # 安装 Playwright(使用精简版以减小镜像体积)
43
  RUN npx playwright install chromium --with-deps --only-shell
44
 
45
- # 创建应用目录
 
 
 
 
 
 
 
 
 
 
 
46
  WORKDIR /app
47
 
48
- # 复制应用代码
49
  COPY src/ /app/src/
50
  COPY entrypoint.sh /app/
51
  COPY config/config.yaml /data/.hermes/config.yaml
52
 
53
  # 创建数据目录
54
- RUN mkdir -p /data/.hermes && \
55
- mkdir -p /app/logs && \
56
  chmod +x /app/entrypoint.sh
57
 
58
  # 设置非 root 用户(Hugging Face Spaces 要求)
59
  RUN useradd -m -u 1000 appuser && \
60
- chown -R appuser:appuser /data && \
61
- chown -R appuser:appuser /app
62
 
63
  USER appuser
64
 
65
- # 暴露端口(Hugging Face Spaces 默认 7860)
 
 
66
  EXPOSE 7860
67
 
68
- # 健康检查
69
- HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
70
  CMD curl -f http://localhost:7860/health || exit 1
71
 
72
- # 启动脚本
73
  ENTRYPOINT ["/app/entrypoint.sh"]
 
2
 
3
  LABEL maintainer="Hermes Agent Community"
4
  LABEL version="0.10.0"
5
+ LABEL description="Hermes Agent v0.10.0 with Web UI on Hugging Face Spaces"
6
 
7
+ # ==================== 环境变量 ====================
8
  ENV PYTHONUNBUFFERED=1
9
  ENV DEBIAN_FRONTEND=noninteractive
10
  ENV HERMES_HOME=/data/.hermes
11
  ENV PYTHONPATH=/app
12
 
13
+ # BFF Server 环境变量
14
+ ENV PORT=7860
15
+ ENV UPSTREAM=http://127.0.0.1:8642
16
+ ENV HERMES_BIN=/usr/local/bin/hermes
17
+ ENV NODE_ENV=production
18
+
19
+ # ==================== 系统依赖 ====================
20
  RUN apt-get update && apt-get install -y \
21
  build-essential \
 
 
22
  ffmpeg \
23
  git \
24
  curl \
25
  unzip \
26
+ ca-certificates \
27
  && rm -rf /var/lib/apt/lists/*
28
 
29
+ # ==================== Node.js v23 ====================
30
+ # hermes-web-ui 要求 Node >= 23.0.0
31
+ RUN ARCH=$(dpkg --print-architecture) \
32
+ && if [ "$ARCH" = "amd64" ]; then NODE_ARCH="x64"; else NODE_ARCH="$ARCH"; fi \
33
+ && echo "Installing Node.js v23.11.0 for ${NODE_ARCH}" \
34
+ && curl -fsSL "https://nodejs.org/dist/v23.11.0/node-v23.11.0-linux-${NODE_ARCH}.tar.gz" \
35
+ -o /tmp/node.tar.gz \
36
+ && tar -xzf /tmp/node.tar.gz -C /usr/local --strip-components=1 \
37
+ && rm -f /tmp/node.tar.gz \
38
+ && node --version \
39
+ && npm --version
40
+
41
+ # ==================== 工具安装 ====================
42
+ # yq: 运行时修改 config.yaml
43
  RUN curl -sL https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -o /usr/bin/yq && \
44
  chmod +x /usr/bin/yq
45
 
46
+ # ==================== Python 依赖 ====================
47
  COPY requirements.txt /tmp/
48
  RUN pip install --no-cache-dir -r /tmp/requirements.txt
49
 
50
+ # ==================== Hermes Agent ====================
51
+ # 克隆并安装 Hermes Agent(不再构建内置 Dashboard 前端,由 hermes-web-ui 替代)
52
  RUN git clone --depth 1 https://github.com/NousResearch/hermes-agent.git /tmp/hermes-agent && \
53
+ pip install --no-cache-dir /tmp/hermes-agent[all] && \
54
+ rm -rf /tmp/hermes-agent
 
 
 
 
55
 
56
+ # Playwright 浏览器(Hermes Agent 工具调用需要)
57
  RUN npx playwright install chromium --with-deps --only-shell
58
 
59
+ # ==================== Hermes Web UI ====================
60
+ # 克隆、构建、精简 hermes-web-ui
61
+ RUN git clone --depth 1 https://github.com/EKKOLearnAI/hermes-web-ui.git /tmp/hermes-web-ui && \
62
+ cd /tmp/hermes-web-ui && \
63
+ npm install && \
64
+ npm run build && \
65
+ npm prune --omit=dev && \
66
+ mkdir -p /opt/hermes-web-ui && \
67
+ cp -r dist node_modules package.json /opt/hermes-web-ui/ && \
68
+ rm -rf /tmp/hermes-web-ui
69
+
70
+ # ==================== 应用代码 ====================
71
  WORKDIR /app
72
 
 
73
  COPY src/ /app/src/
74
  COPY entrypoint.sh /app/
75
  COPY config/config.yaml /data/.hermes/config.yaml
76
 
77
  # 创建数据目录
78
+ RUN mkdir -p /data/.hermes /data/.hermes-web-ui /app/logs && \
 
79
  chmod +x /app/entrypoint.sh
80
 
81
  # 设置非 root 用户(Hugging Face Spaces 要求)
82
  RUN useradd -m -u 1000 appuser && \
83
+ chown -R appuser:appuser /data /opt/hermes-web-ui /app
 
84
 
85
  USER appuser
86
 
87
+ # ==================== 运行配置 ====================
88
+ # 7860: BFF Server (Web UI 入口,HF Spaces 要求)
89
+ # 8642: Gateway API Server (BFF 的上游代理目标,仅容器内部)
90
  EXPOSE 7860
91
 
92
+ HEALTHCHECK --interval=30s --timeout=10s --start-period=90s --retries=3 \
 
93
  CMD curl -f http://localhost:7860/health || exit 1
94
 
 
95
  ENTRYPOINT ["/app/entrypoint.sh"]
config/config.yaml CHANGED
@@ -55,6 +55,12 @@ delegation:
55
  max_iterations: 50
56
  reasoning_effort: "medium"
57
 
 
 
 
 
 
 
58
  # 终端配置
59
  terminal:
60
  backend: local
 
55
  max_iterations: 50
56
  reasoning_effort: "medium"
57
 
58
+ # API Server 配置 (Web UI BFF 的上游代理目标)
59
+ api_server:
60
+ enabled: true
61
+ port: 8642
62
+ host: "0.0.0.0"
63
+
64
  # 终端配置
65
  terminal:
66
  backend: local
src/data_sync.py CHANGED
@@ -50,6 +50,7 @@ class DatasetManager:
50
  'state_db': self.hermes_home / 'state.db',
51
  'logs': self.hermes_home / 'logs',
52
  'cron': self.hermes_home / 'cron',
 
53
  }
54
 
55
  def validate(self) -> bool:
@@ -81,6 +82,7 @@ class DatasetManager:
81
  (self.temp_dir / 'state').mkdir()
82
  (self.temp_dir / 'logs').mkdir()
83
  (self.temp_dir / 'cron').mkdir()
 
84
 
85
  # 复制文件
86
  try:
@@ -124,6 +126,11 @@ class DatasetManager:
124
  if self.path_mapping['cron'].exists():
125
  shutil.copytree(self.path_mapping['cron'], self.temp_dir / 'cron', dirs_exist_ok=True)
126
 
 
 
 
 
 
127
  # 添加元数据
128
  metadata = {
129
  'timestamp': datetime.now().isoformat(),
@@ -215,6 +222,7 @@ class DatasetManager:
215
  'state/state.db': self.path_mapping['state_db'],
216
  'logs': self.path_mapping['logs'],
217
  'cron': self.path_mapping['cron'],
 
218
  }
219
 
220
  # 仅在明确要求时恢复 config.yaml(默认跳过)
 
50
  'state_db': self.hermes_home / 'state.db',
51
  'logs': self.hermes_home / 'logs',
52
  'cron': self.hermes_home / 'cron',
53
+ 'webui_token': Path('/data/.hermes-web-ui') / '.token',
54
  }
55
 
56
  def validate(self) -> bool:
 
82
  (self.temp_dir / 'state').mkdir()
83
  (self.temp_dir / 'logs').mkdir()
84
  (self.temp_dir / 'cron').mkdir()
85
+ (self.temp_dir / 'webui').mkdir()
86
 
87
  # 复制文件
88
  try:
 
126
  if self.path_mapping['cron'].exists():
127
  shutil.copytree(self.path_mapping['cron'], self.temp_dir / 'cron', dirs_exist_ok=True)
128
 
129
+ # WebUI 认证 Token
130
+ if self.path_mapping['webui_token'].exists():
131
+ (self.temp_dir / 'webui').mkdir(exist_ok=True)
132
+ shutil.copy2(self.path_mapping['webui_token'], self.temp_dir / 'webui' / '.token')
133
+
134
  # 添加元数据
135
  metadata = {
136
  'timestamp': datetime.now().isoformat(),
 
222
  'state/state.db': self.path_mapping['state_db'],
223
  'logs': self.path_mapping['logs'],
224
  'cron': self.path_mapping['cron'],
225
+ 'webui/.token': self.path_mapping['webui_token'],
226
  }
227
 
228
  # 仅在明确要求时恢复 config.yaml(默认跳过)