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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# HuggingMes + Hermes WebUI — merged deployment for Hugging Face Spaces
|
| 2 |
+
# Base: NousResearch Hermes Agent (ships Hermes CLI, gateway, dashboard, Python venv)
|
| 3 |
+
|
| 4 |
+
ARG HERMES_AGENT_VERSION=latest
|
| 5 |
+
FROM nousresearch/hermes-agent:${HERMES_AGENT_VERSION}
|
| 6 |
+
|
| 7 |
+
ARG WEBUI_REF=master
|
| 8 |
+
|
| 9 |
+
USER root
|
| 10 |
+
|
| 11 |
+
# System deps (mirrors HuggingMes) + git/nodejs for WebUI checkout + router
|
| 12 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 13 |
+
ca-certificates \
|
| 14 |
+
curl \
|
| 15 |
+
jq \
|
| 16 |
+
git \
|
| 17 |
+
python3 \
|
| 18 |
+
nodejs \
|
| 19 |
+
npm \
|
| 20 |
+
chromium \
|
| 21 |
+
libnss3 \
|
| 22 |
+
libatk1.0-0 \
|
| 23 |
+
libatk-bridge2.0-0 \
|
| 24 |
+
libdrm2 \
|
| 25 |
+
libgbm1 \
|
| 26 |
+
libxcomposite1 \
|
| 27 |
+
libxdamage1 \
|
| 28 |
+
libxrandr2 \
|
| 29 |
+
libxkbcommon0 \
|
| 30 |
+
libx11-6 \
|
| 31 |
+
libxext6 \
|
| 32 |
+
libxfixes3 \
|
| 33 |
+
libasound2 \
|
| 34 |
+
fonts-dejavu-core \
|
| 35 |
+
fonts-liberation \
|
| 36 |
+
fonts-noto-color-emoji \
|
| 37 |
+
&& rm -rf /var/lib/apt/lists/* \
|
| 38 |
+
&& uv pip install --python /opt/hermes/.venv/bin/python --no-cache-dir \
|
| 39 |
+
huggingface_hub hf_transfer pyyaml
|
| 40 |
+
|
| 41 |
+
# Clone nesquena/hermes-webui (install deps into the agent venv so imports resolve)
|
| 42 |
+
RUN git clone --depth 1 --branch ${WEBUI_REF} \
|
| 43 |
+
https://github.com/nesquena/hermes-webui.git /opt/hermes-webui \
|
| 44 |
+
&& ( [ -f /opt/hermes-webui/requirements.txt ] \
|
| 45 |
+
&& /opt/hermes/.venv/bin/pip install --no-cache-dir -r /opt/hermes-webui/requirements.txt \
|
| 46 |
+
|| true ) \
|
| 47 |
+
&& chown -R hermes:hermes /opt/hermes-webui
|
| 48 |
+
|
| 49 |
+
# HuggingMes-style integration scripts (vendored from somratpro/HuggingMes)
|
| 50 |
+
COPY --chown=hermes:hermes start.sh /opt/huggingmes/start.sh
|
| 51 |
+
COPY --chown=hermes:hermes health-server.js /opt/huggingmes/health-server.js
|
| 52 |
+
COPY --chown=hermes:hermes hermes-sync.py /opt/huggingmes/hermes-sync.py
|
| 53 |
+
COPY --chown=hermes:hermes cloudflare-proxy-setup.py /opt/huggingmes/cloudflare-proxy-setup.py
|
| 54 |
+
COPY --chown=hermes:hermes cloudflare-keepalive-setup.py /opt/huggingmes/cloudflare-keepalive-setup.py
|
| 55 |
+
|
| 56 |
+
RUN chmod +x \
|
| 57 |
+
/opt/huggingmes/start.sh \
|
| 58 |
+
/opt/huggingmes/hermes-sync.py \
|
| 59 |
+
/opt/huggingmes/cloudflare-proxy-setup.py \
|
| 60 |
+
/opt/huggingmes/cloudflare-keepalive-setup.py
|
| 61 |
+
|
| 62 |
+
# Idempotent kanban migration patch (same workaround HuggingMes ships)
|
| 63 |
+
RUN python3 - <<'PY'
|
| 64 |
+
from pathlib import Path
|
| 65 |
+
import sys
|
| 66 |
+
p = Path("/opt/hermes/hermes_cli/kanban_db.py")
|
| 67 |
+
if not p.exists():
|
| 68 |
+
sys.exit(0)
|
| 69 |
+
src = p.read_text(encoding="utf-8")
|
| 70 |
+
sentinel = "# huggingmes-webui: idempotent-alter"
|
| 71 |
+
if sentinel in src:
|
| 72 |
+
sys.exit(0)
|
| 73 |
+
old = (
|
| 74 |
+
' conn.execute(\n'
|
| 75 |
+
' "ALTER TABLE tasks ADD COLUMN consecutive_failures "\n'
|
| 76 |
+
' "INTEGER NOT NULL DEFAULT 0"\n'
|
| 77 |
+
' )'
|
| 78 |
+
)
|
| 79 |
+
new = (
|
| 80 |
+
f' try: {sentinel}\n'
|
| 81 |
+
' conn.execute(\n'
|
| 82 |
+
' "ALTER TABLE tasks ADD COLUMN consecutive_failures "\n'
|
| 83 |
+
' "INTEGER NOT NULL DEFAULT 0"\n'
|
| 84 |
+
' )\n'
|
| 85 |
+
' except Exception:\n'
|
| 86 |
+
' pass'
|
| 87 |
+
)
|
| 88 |
+
if old in src:
|
| 89 |
+
p.write_text(src.replace(old, new), encoding="utf-8")
|
| 90 |
+
print("kanban patch: applied")
|
| 91 |
+
PY
|
| 92 |
+
|
| 93 |
+
# Quiet hermes-webui's per-request access log noise.
|
| 94 |
+
# By default it prints \[webui] {"ts":...,"method":...}\ for EVERY request,
|
| 95 |
+
# which drowns the HF Logs tab once any browser tab is open polling
|
| 96 |
+
# /api/dashboard/status, /api/health/agent, /api/sessions, /sw.js, etc.
|
| 97 |
+
# Patch log_request() to drop 2xx responses for high-frequency poll paths.
|
| 98 |
+
# Errors and chat/streaming paths still log normally.
|
| 99 |
+
RUN python3 - <<'PY'
|
| 100 |
+
from pathlib import Path
|
| 101 |
+
import re
|
| 102 |
+
import sys
|
| 103 |
+
|
| 104 |
+
p = Path("/opt/hermes-webui/server.py")
|
| 105 |
+
if not p.exists():
|
| 106 |
+
sys.exit(0)
|
| 107 |
+
src = p.read_text(encoding="utf-8")
|
| 108 |
+
sentinel = "# huggingmes-webui: quiet-poll-paths"
|
| 109 |
+
if sentinel in src:
|
| 110 |
+
sys.exit(0)
|
| 111 |
+
|
| 112 |
+
old = (
|
| 113 |
+
" def log_request(self, code: str='-', size: str='-') -> None:\n"
|
| 114 |
+
" \"\"\"Structured JSON logs for each request.\"\"\"\n"
|
| 115 |
+
" import json as _json\n"
|
| 116 |
+
" duration_ms = round((time.time() - getattr(self, '_req_t0', time.time())) * 1000, 1)\n"
|
| 117 |
+
" record = _json.dumps({\n"
|
| 118 |
+
" 'ts': time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()),\n"
|
| 119 |
+
" 'method': self.command or '-',\n"
|
| 120 |
+
" 'path': self.path or '-',\n"
|
| 121 |
+
" 'status': int(code) if str(code).isdigit() else code,\n"
|
| 122 |
+
" 'ms': duration_ms,\n"
|
| 123 |
+
" })\n"
|
| 124 |
+
" print(f'[webui] {record}', flush=True)"
|
| 125 |
+
)
|
| 126 |
+
|
| 127 |
+
new = (
|
| 128 |
+
" _QUIET_POLL_PATHS = ( " + sentinel + "\n"
|
| 129 |
+
" '/api/health/agent', '/api/dashboard/status',\n"
|
| 130 |
+
" '/api/dashboard/config', '/api/sessions', '/api/profiles',\n"
|
| 131 |
+
" '/api/profile/active', '/api/onboarding/status',\n"
|
| 132 |
+
" '/api/insights', '/api/system/health',\n"
|
| 133 |
+
" '/api/settings', '/api/projects', '/api/reasoning',\n"
|
| 134 |
+
" '/api/models', '/api/chat/stream/status',\n"
|
| 135 |
+
" '/api/git-info', '/sw.js', '/health',\n"
|
| 136 |
+
" )\n"
|
| 137 |
+
" _QUIET_PREFIXES = ('/static/', '/session/static/', '/assets/')\n"
|
| 138 |
+
"\n"
|
| 139 |
+
" def log_request(self, code: str='-', size: str='-') -> None:\n"
|
| 140 |
+
" \"\"\"Structured JSON logs for each request, skipping noisy polls.\"\"\"\n"
|
| 141 |
+
" # Always log non-2xx so 401/404/5xx remain visible.\n"
|
| 142 |
+
" try:\n"
|
| 143 |
+
" status_int = int(code) if str(code).isdigit() else 0\n"
|
| 144 |
+
" except Exception:\n"
|
| 145 |
+
" status_int = 0\n"
|
| 146 |
+
" path = (self.path or '').split('?', 1)[0]\n"
|
| 147 |
+
" if 200 <= status_int < 400:\n"
|
| 148 |
+
" if path in self._QUIET_POLL_PATHS:\n"
|
| 149 |
+
" return\n"
|
| 150 |
+
" for pref in self._QUIET_PREFIXES:\n"
|
| 151 |
+
" if path.startswith(pref):\n"
|
| 152 |
+
" return\n"
|
| 153 |
+
" import json as _json\n"
|
| 154 |
+
" duration_ms = round((time.time() - getattr(self, '_req_t0', time.time())) * 1000, 1)\n"
|
| 155 |
+
" record = _json.dumps({\n"
|
| 156 |
+
" 'ts': time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()),\n"
|
| 157 |
+
" 'method': self.command or '-',\n"
|
| 158 |
+
" 'path': self.path or '-',\n"
|
| 159 |
+
" 'status': int(code) if str(code).isdigit() else code,\n"
|
| 160 |
+
" 'ms': duration_ms,\n"
|
| 161 |
+
" })\n"
|
| 162 |
+
" print(f'[webui] {record}', flush=True)"
|
| 163 |
+
)
|
| 164 |
+
|
| 165 |
+
if old in src:
|
| 166 |
+
p.write_text(src.replace(old, new), encoding="utf-8")
|
| 167 |
+
print("webui log-quiet patch: applied")
|
| 168 |
+
else:
|
| 169 |
+
print("webui log-quiet patch: pattern not found, skipping")
|
| 170 |
+
PY
|
| 171 |
+
|
| 172 |
+
# Fix permissions so hermes user can self-update packages
|
| 173 |
+
RUN chown -R hermes:hermes /opt/hermes/.venv
|
| 174 |
+
|
| 175 |
+
# Keep hermes CLI on PATH for all shell types (login/interactive/non-interactive)
|
| 176 |
+
RUN echo 'export PATH="/opt/hermes/.venv/bin:/opt/data/.local/bin:$PATH"' \
|
| 177 |
+
> /etc/profile.d/hermes-venv.sh
|
| 178 |
+
|
| 179 |
+
ENV HERMES_HOME=/opt/data \
|
| 180 |
+
HUGGINGMES_APP_DIR=/opt/huggingmes \
|
| 181 |
+
HERMES_WEBUI_REPO=/opt/hermes-webui \
|
| 182 |
+
HERMES_AGENT_VERSION=${HERMES_AGENT_VERSION} \
|
| 183 |
+
PYTHONUNBUFFERED=1 \
|
| 184 |
+
HF_HUB_ENABLE_HF_TRANSFER=1 \
|
| 185 |
+
PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/usr/bin/chromium
|
| 186 |
+
|
| 187 |
+
EXPOSE 7861
|
| 188 |
+
|
| 189 |
+
HEALTHCHECK --interval=30s --timeout=5s --start-period=120s \
|
| 190 |
+
CMD curl -fsS http://localhost:7861/health || exit 1
|
| 191 |
+
|
| 192 |
+
USER hermes
|
| 193 |
+
ENTRYPOINT ["/opt/huggingmes/start.sh"]
|