FROM python:3.11-slim LABEL maintainer="Hermes Agent Community" LABEL version="0.10.0" LABEL description="Hermes Agent v0.10.0 with Web UI on Hugging Face Spaces" # ==================== 环境变量 ==================== ENV PYTHONUNBUFFERED=1 ENV DEBIAN_FRONTEND=noninteractive ENV HERMES_HOME=/data/.hermes ENV PYTHONPATH=/app # BFF Server 环境变量(构建阶段) ENV PORT=7860 ENV UPSTREAM=http://127.0.0.1:8642 ENV HERMES_BIN=/usr/local/bin/hermes # 注意:NODE_ENV=production 不能在此设置! # npm install 在 NODE_ENV=production 时会跳过 devDependencies, # 导致 vue-tsc 等构建工具缺失。NODE_ENV 在运行时阶段再设置。 # ==================== 系统依赖 ==================== RUN apt-get update && apt-get install -y \ make gcc g++ \ ffmpeg \ git \ curl \ unzip \ ca-certificates \ && rm -rf /var/lib/apt/lists/* # ==================== Node.js v23 ==================== # hermes-web-ui 要求 Node >= 23.0.0 RUN ARCH=$(dpkg --print-architecture) \ && if [ "$ARCH" = "amd64" ]; then NODE_ARCH="x64"; else NODE_ARCH="$ARCH"; fi \ && echo "Installing Node.js v23.11.0 for ${NODE_ARCH}" \ && curl -fsSL "https://nodejs.org/dist/v23.11.0/node-v23.11.0-linux-${NODE_ARCH}.tar.gz" \ -o /tmp/node.tar.gz \ && tar -xzf /tmp/node.tar.gz -C /usr/local --strip-components=1 \ && rm -f /tmp/node.tar.gz \ && node --version \ && npm --version # ==================== 工具安装 ==================== # yq: 运行时修改 config.yaml RUN curl -sL https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -o /usr/bin/yq && \ chmod +x /usr/bin/yq # ==================== Code Server ==================== RUN curl -fsSL https://code-server.dev/install.sh | sh # ==================== Python 依赖 ==================== COPY requirements.txt /tmp/ RUN pip install --no-cache-dir --prefer-binary -r /tmp/requirements.txt # ==================== Hermes Agent ==================== # 克隆并安装 Hermes Agent(不再构建内置 Dashboard 前端,由 hermes-web-ui 替代) # 注意:必须保留源码到 /usr/local/lib/hermes-agent,不能删除! # hermes-web-ui 的桥接程序 (hermes_bridge.py) 需要 run_agent.py 来创建 Unix Socket RUN git clone --depth 1 https://github.com/NousResearch/hermes-agent.git /usr/local/lib/hermes-agent && \ pip install uv && \ cd /usr/local/lib/hermes-agent && \ uv pip install --system -e .[all] && \ rm -rf /root/.cache/pip # Playwright 浏览器(Hermes Agent 工具调用需要) RUN npx playwright install chromium --with-deps --only-shell && \ rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/* # ==================== Hermes Web UI ==================== # 直接安装 npm 预构建包(已包含编译好的 dist/ 目录),跳过源码编译节省 3-8 分钟 # 默认版本 0.6.3,可通过 --build-arg HERMES_WEB_UI_VERSION=新版本 覆盖 # HF Spaces: 在 Settings -> Repository secrets 添加同名变量即可注入 ARG HERMES_WEB_UI_VERSION=0.6.36 RUN mkdir -p /opt/hermes-web-ui && cd /opt/hermes-web-ui && \ npm init -y && \ npm install hermes-web-ui@${HERMES_WEB_UI_VERSION} && \ ln -sf node_modules/hermes-web-ui/dist dist && \ ln -sf node_modules/hermes-web-ui/package.json package.json && \ rm -rf /root/.npm # ==================== 应用代码 ==================== WORKDIR /app COPY src/ /app/src/ COPY entrypoint.sh /app/ COPY config/config.yaml /data/.hermes/config.yaml # 创建数据目录 RUN mkdir -p /data/.hermes /data/.hermes-web-ui /app/logs && \ chmod +x /app/entrypoint.sh # 设置非 root 用户(Hugging Face Spaces 要求) RUN useradd -m -u 1000 appuser && \ ln -sf /data/.hermes /home/appuser/.hermes && \ chown -R appuser:appuser /data /opt/hermes-web-ui /app USER appuser # ==================== 运行时环境变量 ==================== # 构建阶段不设 NODE_ENV=production(会导致 npm install 跳过 devDependencies) # 此处设置,仅影响运行时行为 ENV NODE_ENV=production # 7860: BFF Server (Web UI 入口,HF Spaces 要求) # 8642: Gateway API Server (BFF 的上游代理目标,仅容器内部) # 8443: Code Server (容器内部访问) EXPOSE 7860 8443 HEALTHCHECK --interval=30s --timeout=10s --start-period=90s --retries=3 \ CMD curl -f http://localhost:7860/health || exit 1 ENTRYPOINT ["/app/entrypoint.sh"]