Spaces:
Paused
Paused
Update Dockerfile
Browse files1234534 unmodified lines4041424344454647484950143 unmodified lines194195196197198199200225 unmodified lines4264274284294304318 unmodified lines44044144244344444530 unmodified lines47647747847948048148248348448548648748848957 unmodified lines54754854955055155235 unmodified lines5885895905915925935949 unmodified lines604605606607608609122 unmodified lines732733734735736737738739740741# ============================================================# Hermes Agent β Self-contained HF Spaces deployment (Stable v7.0)# Single Dockerfile: Gateway + Dashboard + Chat WebUI + Router## HOW TO DEPLOY:34 unmodified linesHF_HUB_ENABLE_HF_TRANSFER=1 \TERM=xterm-256color \SHELL=/bin/bash \SYNC_INTERVAL=30# ββ System deps & HF CLI installation ββββββββββββββββββββββββRUN apt-get update && apt-get install -y --no-install-recommends \ca-certificates curl jq git nodejs npm python3 netcat-openbsd tar gzip unzip dnsutils \&& rm -rf /var/lib/apt/lists/* \&& uv pip install --python /opt/hermes/.venv/bin/python \--no-cache-dir "huggingface_hub>=0.22" pyyaml \143 unmodified linesfor (var i = 0; i < params.length; i++) {var pair = params[i].split('=');// FIX: Correctly check array key pair elements to support iframe token SSO query bypassesif (pair === 'token' && decodeURIComponent(pair || '').trim() === cleanGatewayToken) {return true;}}225 unmodified lines});ENDJS# ββ Write start.sh ββββββββββββββββββββββββββββββββββββββββββββRUN cat > /opt/start.sh << 'ENDSH'#!/usr/bin/env bash8 unmodified linesecho "β Hermes Agent β HF Spaces bootloader β"echo "ββββββββββββββββββββββββββββββββββββββββββββ"# ββ 1. BACKGROUND FRONTEND UPDATES ββββββββββββββββββββββββββββecho "[boot] π Checking for WebUI updates in background..."(cd /opt/hermes-webui && git pull >/dev/null 2>&1) &30 unmodified linescursor = conn.cursor()cursor.execute("PRAGMA integrity_check;")res = cursor.fetchone()# FIX: Check res tuple directly to ensure SQLite checking is fully operationalif res and res == "ok":cursor.execute("PRAGMA journal_mode=WAL;")cursor.execute("PRAGMA synchronous=NORMAL;")conn.commit()print(f"[boot-recover] Database OK and WAL enabled: {fname}")else:raise Exception(f"Integrity check failed: {res if res else 'Unknown'}")conn.close()except Exception as e:print(f"[boot-recover] SQLite database corrupt/locked: {db_path} ({e})")57 unmodified linesupsert_key "API_SERVER_KEY" "${API_SERVER_KEY:-}"upsert_key "TELEGRAM_API_BASE" "${TELEGRAM_API_BASE:-}"if [ -n "${TELEGRAM_BOT_TOKEN:-}" ]; thenupsert_key "TELEGRAM_BOT_TOKEN" "${TELEGRAM_BOT_TOKEN}"USERS="${TELEGRAM_ALLOWED_USERS:-}"35 unmodified linesmodel:provider: ${PROVIDER}default: "${MODEL}"YAMLfi# ββ 9. START SERVICES βββββββββββββββββββββββββββββββββββββββββ9 unmodified linesOPENROUTER_API_KEY="${OPENROUTER_API_KEY:-}" \OPENAI_API_KEY="${OPENAI_API_KEY:-}" \ANTHROPIC_API_KEY="${ANTHROPIC_API_KEY:-}" \hermes gateway run > "$HH/logs/gateway.log" 2>&1 &echo "[boot] ποΈ Starting Hermes Dashboard (port 9119)..."122 unmodified lines&& mkdir -p /home/hermes \&& rm -rf /home/hermes/.hermes && ln -sf /data /home/hermes/.hermes \&& rm -rf /opt/data && ln -sf /data /opt/data \&& touch /home/hermes/.bashrc && echo "export PATH=\"/opt/hermes/.venv/bin:/opt/data/.local/bin:\$PATH\"" >> /home/hermes/.bashrc \&& chown -R hermes:hermes /data /home/hermes /opt/hermes /opt/hermes-webui /opt/router /opt/start.sh \&& chown -h hermes:hermes /home/hermes/.hermes /opt/data \&& chmod -R 777 /dataEXPOSE 78601234534 unmodified lines40414243444546474849505152535455565758596061626364656667143 unmodified lines211212213214215216217225 unmodified lines4434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734748 unmodified lines48348448548648748848949049149249349449549649730 unmodified lines52852953053153253353453553653753853954054157 unmodified lines59960060160260360460560660760860935 unmodified lines6456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866879 unmodified lines697698699700701702703704122 unmodified lines827828829830831832833834835836837838839840841842843844845# ============================================================# Hermes Agent β Self-contained HF Spaces deployment (Stable v7.1)# Single Dockerfile: Gateway + Dashboard + Chat WebUI + Router## HOW TO DEPLOY:34 unmodified linesHF_HUB_ENABLE_HF_TRANSFER=1 \TERM=xterm-256color \SHELL=/bin/bash \SYNC_INTERVAL=30 \# ββ BROWSER FIX: Force --no-sandbox + --disable-dev-shm-usage for ALL# Chromium launches. HuggingFace Spaces (like most containers/VMs) runs# with AppArmor unprivileged user namespace restrictions enabled, which# causes Chromium to refuse to start and agent-browser to time out after# 60s. These flags are the standard fix for containerised environments.# Setting AGENT_BROWSER_CHROME_FLAGS here overrides Hermes's auto-detect# and guarantees the flags are always injected at the env level.AGENT_BROWSER_CHROME_FLAGS="--no-sandbox,--disable-dev-shm-usage,--disable-gpu,--disable-setuid-sandbox,--disable-software-rasterizer" \# Ensure Playwright Chromium cache is in a writable path for hermes userPLAYWRIGHT_BROWSERS_PATH=/opt/hermes/.playwright# ββ System deps & HF CLI installation ββββββββββββββββββββββββRUN apt-get update && apt-get install -y --no-install-recommends \ca-certificates curl jq git nodejs npm python3 netcat-openbsd tar gzip unzip dnsutils \# ββ BROWSER FIX: Chromium runtime deps needed for headless operation# in a container without a display. These prevent the "missing shared# library" class of errors that also cause browser_navigate to fail.libglib2.0-0 libnss3 libnspr4 libatk1.0-0 libatk-bridge2.0-0 \libcups2 libdrm2 libdbus-1-3 libxcb1 libxkbcommon0 libx11-6 \libxcomposite1 libxdamage1 libxext6 libxfixes3 libxrandr2 \libgbm1 libpango-1.0-0 libcairo2 libasound2 libatspi2.0-0 \&& rm -rf /var/lib/apt/lists/* \&& uv pip install --python /opt/hermes/.venv/bin/python \--no-cache-dir "huggingface_hub>=0.22" pyyaml \143 unmodified linesfor (var i = 0; i < params.length; i++) {var pair = params[i].split('=');// FIX: Correctly check array key pair elements to support iframe token SSO query bypassesif (pair[0] === 'token' && decodeURIComponent(pair[1] || '').trim() === cleanGatewayToken) {return true;}}225 unmodified lines});ENDJS# ββ BROWSER FIX: Pre-write agent-browser config with no-sandbox flags βββββββββ# This config file is read by agent-browser (Vercel's browser CLI that Hermes# uses as its local Chromium driver). Writing it at build time ensures the flags# are present even before start.sh runs, so the very first browser_navigate call# does not time out.RUN mkdir -p /opt/hermes/.agent-browser \&& cat > /opt/hermes/.agent-browser/config.json << 'ENDJSON'{"$schema": "https://agent-browser.dev/schema.json","args": "--no-sandbox,--disable-dev-shm-usage,--disable-gpu,--disable-setuid-sandbox,--disable-software-rasterizer","headless": true}ENDJSON# ββ BROWSER FIX: Install Playwright Chromium as root into a shared path βββββββ# The base image installs Playwright under /root/.cache which is not accessible# by the hermes user. We reinstall it into PLAYWRIGHT_BROWSERS_PATH=/opt/hermes/.playwright# (set in ENV above) so the hermes user can find and execute Chromium.# We also run `npx playwright install-deps chromium` to pull any missing OS libs.RUN mkdir -p /opt/hermes/.playwright \&& PLAYWRIGHT_BROWSERS_PATH=/opt/hermes/.playwright \npx --yes playwright install chromium \&& PLAYWRIGHT_BROWSERS_PATH=/opt/hermes/.playwright \npx playwright install-deps chromium 2>/dev/null || true \&& chown -R hermes:hermes /opt/hermes/.playwright# ββ Write start.sh ββββββββββββββββββββββββββββββββββββββββββββRUN cat > /opt/start.sh << 'ENDSH'#!/usr/bin/env bash8 unmodified linesecho "β Hermes Agent β HF Spaces bootloader β"echo "ββββββββββββββββββββββββββββββββββββββββββββ"# ββ 0. BROWSER FIX: Ensure /tmp agent-browser socket dir is writable ββββββββββ# agent-browser creates Unix socket files under /tmp/agent-browser-* for IPC.# We pre-create the subdir and make it world-writable.# NOTE: We do NOT chmod /tmp itself β HF Spaces runs as an unprivileged user# who cannot chmod system dirs. Attempting it crashes the boot under set -e.# /tmp is already world-writable on all HF Space base images; no chmod needed.mkdir -p /tmp/agent-browser-sockets || truechmod 777 /tmp/agent-browser-sockets 2>/dev/null || true# ββ 1. BACKGROUND FRONTEND UPDATES ββββββββββββββββββββββββββββecho "[boot] π Checking for WebUI updates in background..."(cd /opt/hermes-webui && git pull >/dev/null 2>&1) &30 unmodified linescursor = conn.cursor()cursor.execute("PRAGMA integrity_check;")res = cursor.fetchone()# FIX: res is a tuple e.g. ("ok",) β compare the first elementif res and res[0] == "ok":cursor.execute("PRAGMA journal_mode=WAL;")cursor.execute("PRAGMA synchronous=NORMAL;")conn.commit()print(f"[boot-recover] Database OK and WAL enabled: {fname}")else:raise Exception(f"Integrity check failed: {res[0] if res else 'Unknown'}")conn.close()except Exception as e:print(f"[boot-recover] SQLite database corrupt/locked: {db_path} ({e})")57 unmodified linesupsert_key "API_SERVER_KEY" "${API_SERVER_KEY:-}"upsert_key "TELEGRAM_API_BASE" "${TELEGRAM_API_BASE:-}"# ββ BROWSER FIX: Always persist the Chrome flags into .env so Hermes gateway# picks them up even if the ENV block above was somehow not inherited ββββββββββupsert_key "AGENT_BROWSER_CHROME_FLAGS" "--no-sandbox,--disable-dev-shm-usage,--disable-gpu,--disable-setuid-sandbox,--disable-software-rasterizer"upsert_key "PLAYWRIGHT_BROWSERS_PATH" "/opt/hermes/.playwright"if [ -n "${TELEGRAM_BOT_TOKEN:-}" ]; thenupsert_key "TELEGRAM_BOT_TOKEN" "${TELEGRAM_BOT_TOKEN}"USERS="${TELEGRAM_ALLOWED_USERS:-}"35 unmodified linesmodel:provider: ${PROVIDER}default: "${MODEL}"# ββ BROWSER: container-safe settings ββββββββββββββββββββββββββ# command_timeout raised from default 30s to 90s to survive slow page loads.# The chromium_args block passes the no-sandbox flags directly to the Hermes# browser layer in addition to the AGENT_BROWSER_CHROME_FLAGS env variable,# so both code paths (agent-browser CLI and Hermes's own Playwright launcher)# get the flags.browser:command_timeout: 90inactivity_timeout: 120chromium_args:- --no-sandbox- --disable-dev-shm-usage- --disable-gpu- --disable-setuid-sandbox- --disable-software-rasterizerYAMLelse# ββ BROWSER FIX: If config.yaml already exists (restored from bucket) but# lacks the browser block, append it. This ensures upgrades and restored# workspaces also get the fix without wiping existing user settings.if ! grep -q "^browser:" "$CFG" 2>/dev/null; thenecho "[boot] π§ Appending browser config block to existing config.yaml..."cat >> "$CFG" << YAML# ββ BROWSER: container-safe settings (auto-appended by bootloader) ββββββββββββbrowser:command_timeout: 90inactivity_timeout: 120chromium_args:- --no-sandbox- --disable-dev-shm-usage- --disable-gpu- --disable-setuid-sandbox- --disable-software-rasterizerYAMLfifi# ββ 9. START SERVICES βββββββββββββββββββββββββββββββββββββββββ9 unmodified linesOPENROUTER_API_KEY="${OPENROUTER_API_KEY:-}" \OPENAI_API_KEY="${OPENAI_API_KEY:-}" \ANTHROPIC_API_KEY="${ANTHROPIC_API_KEY:-}" \AGENT_BROWSER_CHROME_FLAGS="--no-sandbox,--disable-dev-shm-usage,--disable-gpu,--disable-setuid-sandbox,--disable-software-rasterizer" \PLAYWRIGHT_BROWSERS_PATH="/opt/hermes/.playwright" \hermes gateway run > "$HH/logs/gateway.log" 2>&1 &echo "[boot] ποΈ Starting Hermes Dashboard (port 9119)..."122 unmodified lines&& mkdir -p /home/hermes \&& rm -rf /home/hermes/.hermes && ln -sf /data /home/hermes/.hermes \&& rm -rf /opt/data && ln -sf /data /opt/data \&& touch /home/hermes/.bashrc \&& echo "export PATH=\"/opt/hermes/.venv/bin:/opt/data/.local/bin:\$PATH\"" >> /home/hermes/.bashrc \# ββ BROWSER FIX: Also export Playwright and Chrome flags in the interactive# shell so that any terminal commands the agent runs (e.g. npx playwright# or agent-browser) also inherit the no-sandbox configuration ββββββββββββββ&& echo "export PLAYWRIGHT_BROWSERS_PATH=/opt/hermes/.playwright" >> /home/hermes/.bashrc \&& echo "export AGENT_BROWSER_CHROME_FLAGS=\"--no-sandbox,--disable-dev-shm-usage,--disable-gpu,--disable-setuid-sandbox,--disable-software-rasterizer\"" >> /home/hermes/.bashrc \&& chown -R hermes:hermes /data /home/hermes /opt/hermes /opt/hermes-webui /opt/router /opt/start.sh \&& chown -h hermes:hermes /home/hermes/.hermes /opt/data \&& chmod -R 777 /data \# ββ PERMISSION FIX: Ensure the hermes user owns the Playwright browser# cache we installed as root, and the agent-browser config we wrote ββββββββ&& chown -R hermes:hermes /opt/hermes/.playwright /opt/hermes/.agent-browserEXPOSE 7860
Dockerfile+112-8