saadpie commited on
Commit
ba81d94
·
verified ·
1 Parent(s): 0ef553f

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +122 -35
Dockerfile CHANGED
@@ -1,48 +1,135 @@
1
- FROM python:3.10-slim
 
 
 
 
 
2
 
3
- # Install system dependencies
4
  RUN apt-get update && apt-get install -y --no-install-recommends \
5
- git \
6
  curl \
7
- build-essential \
8
- nodejs \
9
- npm \
10
- && rm -rf /var/lib/apt/lists/*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
- # Pre-create all required directory structures
13
- RUN mkdir -p /opt/huggingmes /opt/data /opt/hermes
 
 
 
14
 
15
- # Clone HuggingMes repository into /opt/huggingmes
16
- RUN git clone https://github.com/somratpro/HuggingMes.git /opt/huggingmes
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
- # Set up the exact Python venv expected by start.sh at /opt/hermes/.venv
19
- RUN python3 -m venv /opt/hermes/.venv
20
- ENV PATH="/opt/hermes/.venv/bin:${PATH}"
21
 
22
- # Install Python requirements into the venv
23
- WORKDIR /opt/huggingmes
24
- RUN /opt/hermes/.venv/bin/pip install --no-cache-dir --upgrade pip setuptools wheel
25
- RUN /opt/hermes/.venv/bin/pip install --no-cache-dir pyyaml jupyterlab requests
 
26
 
27
- # Install hermes package if setup.py or pyproject.toml exists
28
- RUN if [ -f setup.py ] || [ -f pyproject.toml ]; then /opt/hermes/.venv/bin/pip install --no-cache-dir -e .; fi
29
- RUN if [ -f requirements.txt ]; then /opt/hermes/.venv/bin/pip install --no-cache-dir -r requirements.txt; fi
30
- RUN if [ -f package.json ]; then npm install; fi
 
 
 
 
 
31
 
32
- # Create HF non-root user (UID 1000) and grant ownership
33
- RUN useradd -m -u 1000 user
34
- RUN chown -R user:user /opt/huggingmes /opt/data /opt/hermes /home/user
 
 
35
 
36
- # Switch to HF user context
37
- USER user
38
- ENV HUGGINGMES_APP_DIR="/opt/huggingmes"
39
- ENV HERMES_HOME="/opt/data"
40
- ENV PATH="/opt/hermes/.venv/bin:/home/user/.local/bin:${PATH}"
41
 
42
- WORKDIR /opt/huggingmes
43
- EXPOSE 7860
44
 
45
- # Ensure start.sh has execution permissions
46
- RUN chmod +x start.sh 2>/dev/null || true
47
 
48
- CMD ["/bin/bash", "./start.sh"]
 
1
+ # HuggingMes - Hermes Agent Gateway for Hugging Face Spaces
2
+
3
+ ARG HERMES_AGENT_VERSION=latest
4
+ FROM nousresearch/hermes-agent:${HERMES_AGENT_VERSION}
5
+
6
+ USER root
7
 
 
8
  RUN apt-get update && apt-get install -y --no-install-recommends \
9
+ ca-certificates \
10
  curl \
11
+ jq \
12
+ sudo \
13
+ python3 \
14
+ python3-venv \
15
+ python3-pip \
16
+ chromium \
17
+ dbus \
18
+ dbus-x11 \
19
+ libnss3 \
20
+ libatk1.0-0 \
21
+ libatk-bridge2.0-0 \
22
+ libdrm2 \
23
+ libgbm1 \
24
+ libxcomposite1 \
25
+ libxdamage1 \
26
+ libxrandr2 \
27
+ libxkbcommon0 \
28
+ libx11-6 \
29
+ libxext6 \
30
+ libxfixes3 \
31
+ fonts-dejavu-core \
32
+ fonts-liberation \
33
+ fonts-noto-color-emoji \
34
+ && (apt-get install -y --no-install-recommends libasound2 2>/dev/null \
35
+ || apt-get install -y --no-install-recommends libasound2t64 2>/dev/null \
36
+ || true) \
37
+ && rm -rf /var/lib/apt/lists/* \
38
+ && uv pip install --python /opt/hermes/.venv/bin/python --no-cache-dir \
39
+ huggingface_hub \
40
+ hf_transfer \
41
+ "jupyterlab>=4.0,<5" \
42
+ "tornado>=6.4" \
43
+ "ipywidgets>=8.1" \
44
+ && printf 'hermes ALL=(ALL) NOPASSWD: ALL\n' > /etc/sudoers.d/hermes \
45
+ && chmod 0440 /etc/sudoers.d/hermes \
46
+ && /usr/sbin/visudo -cf /etc/sudoers.d/hermes
47
+
48
+ COPY --chown=hermes:hermes start.sh /opt/huggingmes/start.sh
49
+ COPY --chown=hermes:hermes health-server.js /opt/huggingmes/health-server.js
50
+ COPY --chown=hermes:hermes hermes-sync.py /opt/huggingmes/hermes-sync.py
51
+ COPY --chown=hermes:hermes cloudflare-proxy-setup.py /opt/huggingmes/cloudflare-proxy-setup.py
52
+ COPY --chown=hermes:hermes cloudflare-keepalive-setup.py /opt/huggingmes/cloudflare-keepalive-setup.py
53
+ COPY --chown=hermes:hermes env-builder.html /opt/huggingmes/env-builder.html
54
+ COPY --chown=hermes:hermes env-builder.js /opt/huggingmes/env-builder.js
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
+ # Patch kanban migration: wrap ALTER TABLE ADD COLUMN in try/except so a
63
+ # persisted DB with the column already present doesn't crash the gateway.
64
+ # Entire block wrapped in try/except — skips silently if Hermes fixes this
65
+ # upstream or the file structure changes.
66
+ RUN python3 - <<'PY'
67
+ import sys
68
+ try:
69
+ from pathlib import Path
70
+
71
+ p = Path("/opt/hermes/hermes_cli/kanban_db.py")
72
+ if not p.exists():
73
+ print("kanban patch: file not found, skipping")
74
+ sys.exit(0)
75
 
76
+ src = p.read_text(encoding="utf-8", errors="replace")
77
+ sentinel = "# huggingmes: idempotent-alter"
78
+ if sentinel in src:
79
+ print("kanban patch: already applied, skipping")
80
+ sys.exit(0)
81
 
82
+ old = (
83
+ ' conn.execute(\n'
84
+ ' "ALTER TABLE tasks ADD COLUMN consecutive_failures "\n'
85
+ ' "INTEGER NOT NULL DEFAULT 0"\n'
86
+ ' )'
87
+ )
88
+ new = (
89
+ f' try: {sentinel}\n'
90
+ ' conn.execute(\n'
91
+ ' "ALTER TABLE tasks ADD COLUMN consecutive_failures "\n'
92
+ ' "INTEGER NOT NULL DEFAULT 0"\n'
93
+ ' )\n'
94
+ ' except Exception:\n'
95
+ ' pass'
96
+ )
97
 
98
+ if old not in src:
99
+ print("kanban patch: pattern not found, may be fixed upstream, skipping")
100
+ sys.exit(0)
101
 
102
+ p.write_text(src.replace(old, new), encoding="utf-8")
103
+ print("kanban patch: applied")
104
+ except Exception as e:
105
+ print(f"kanban patch: error ({e}), skipping", file=sys.stderr)
106
+ PY
107
 
108
+ # hermes v0.17+ self-patches its own Python files at container startup
109
+ # (workspace/startup.sh), but ships them read-only in the image.
110
+ # Make all subdirs traversable first so find reaches every .py file; dirs
111
+ # without execute permission cause find to silently skip them.
112
+ # Use a+w (not u+w): this RUN executes as root during build, but HF Spaces
113
+ # runs the container as an arbitrary non-root UID at runtime — u+w only
114
+ # grants write to the file's owner (root), which the runtime UID isn't.
115
+ RUN find /opt/hermes -type d -exec chmod a+rwx {} + 2>/dev/null || true \
116
+ && find /opt/hermes -name "*.py" -exec chmod a+w {} + 2>/dev/null || true
117
 
118
+ # Ensure hermes CLI is discoverable in ALL shell types (login, interactive,
119
+ # non-interactive). /etc/profile.d/ is sourced by login shells after /etc/profile
120
+ # resets PATH, so this survives even full environment resets.
121
+ RUN echo 'export PATH="/opt/hermes/.venv/bin:/opt/data/.local/bin:$PATH"' \
122
+ > /etc/profile.d/hermes-venv.sh
123
 
124
+ ENV HERMES_HOME=/opt/data \
125
+ HUGGINGMES_APP_DIR=/opt/huggingmes \
126
+ HERMES_AGENT_VERSION=${HERMES_AGENT_VERSION} \
127
+ PYTHONUNBUFFERED=1 \
128
+ PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/usr/bin/chromium
129
 
130
+ EXPOSE 7861
 
131
 
132
+ HEALTHCHECK --interval=30s --timeout=5s --start-period=60s \
133
+ CMD curl -fsS http://localhost:7861/health || exit 1
134
 
135
+ CMD ["/opt/huggingmes/start.sh"]