Spaces:
Paused
Paused
Arshit Malik commited on
Commit ·
aa49469
1
Parent(s): a326bb7
fix: use official openclaw image (all deps resolved), remove health daemon, smart proxy on 8080
Browse files- Dockerfile +12 -9
- start.sh +38 -32
Dockerfile
CHANGED
|
@@ -1,16 +1,19 @@
|
|
| 1 |
-
FROM
|
| 2 |
|
| 3 |
-
|
| 4 |
-
curl nginx cron procps git zstd \
|
| 5 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
RUN curl -fsSL https://ollama.com/install.sh | sh
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
tenacity \
|
| 12 |
-
"openclaw==2026.3.20" \
|
| 13 |
-
huggingface_hub
|
| 14 |
|
| 15 |
RUN printf 'server {\n listen 7860;\n location / {\n proxy_pass http://127.0.0.1:8080;\n proxy_http_version 1.1;\n proxy_set_header Upgrade $http_upgrade;\n proxy_set_header Connection "upgrade";\n proxy_set_header Host $host;\n }\n}\n' > /etc/nginx/sites-available/default
|
| 16 |
|
|
|
|
| 1 |
+
FROM ghcr.io/openclaw/openclaw:latest
|
| 2 |
|
| 3 |
+
USER root
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
# Kill the HuggingClaw health-check daemon that causes Space pauses
|
| 6 |
+
RUN rm -f /etc/cron.d/*health* /etc/cron.d/*hc* 2>/dev/null; \
|
| 7 |
+
rm -f /usr/local/bin/*health* /usr/local/bin/*hc* 2>/dev/null; \
|
| 8 |
+
pkill -f health 2>/dev/null; \
|
| 9 |
+
echo "Health daemon removed"
|
| 10 |
+
|
| 11 |
+
# Install Ollama + deps
|
| 12 |
+
RUN apt-get update && apt-get install -y curl nginx zstd cron procps git && rm -rf /var/lib/apt/lists/*
|
| 13 |
RUN curl -fsSL https://ollama.com/install.sh | sh
|
| 14 |
|
| 15 |
+
# Install huggingface_hub for model download
|
| 16 |
+
RUN pip install --no-cache-dir huggingface_hub
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
RUN printf 'server {\n listen 7860;\n location / {\n proxy_pass http://127.0.0.1:8080;\n proxy_http_version 1.1;\n proxy_set_header Upgrade $http_upgrade;\n proxy_set_header Connection "upgrade";\n proxy_set_header Host $host;\n }\n}\n' > /etc/nginx/sites-available/default
|
| 19 |
|
start.sh
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
#!/bin/bash
|
| 2 |
set -e
|
| 3 |
|
| 4 |
-
echo "[boot] Pulling OpenClaw state..."
|
| 5 |
python3 -c "
|
| 6 |
import sys, os; sys.path.insert(0, '/app')
|
| 7 |
HF_TOKEN = os.environ.get('HF_TOKEN', '')
|
|
@@ -63,6 +63,7 @@ git config --global user.name "YT Pipeline Bot"
|
|
| 63 |
git config --global user.email "yt-pipe-bot@hf.space"
|
| 64 |
git clone https://arshitmalik:${HF_TOKEN}@huggingface.co/spaces/arshitmalik/yt-flow /app/yt-flow 2>/dev/null || true
|
| 65 |
|
|
|
|
| 66 |
cat > /tmp/backup.sh << 'CRONEOF'
|
| 67 |
#!/bin/bash
|
| 68 |
python3 -c "
|
|
@@ -88,41 +89,46 @@ CRONEOF
|
|
| 88 |
chmod +x /tmp/backup.sh
|
| 89 |
echo "*/15 * * * * /tmp/backup.sh" | crontab -
|
| 90 |
|
| 91 |
-
#
|
| 92 |
python3 -c "
|
| 93 |
-
import http.server, urllib.request
|
| 94 |
-
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
| 96 |
try:
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
self.end_headers()
|
| 101 |
-
self.wfile.write(
|
| 102 |
-
except:
|
| 103 |
self.send_response(200)
|
| 104 |
self.end_headers()
|
| 105 |
-
self.wfile.write(b'OpenClaw
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
), timeout=30)
|
| 113 |
-
self.send_response(r.status)
|
| 114 |
-
self.send_header('Content-Type', r.headers.get('Content-Type','text/plain'))
|
| 115 |
-
self.end_headers()
|
| 116 |
-
self.wfile.write(r.read())
|
| 117 |
-
except:
|
| 118 |
-
self.send_response(502)
|
| 119 |
-
self.end_headers()
|
| 120 |
-
self.wfile.write(b'Gateway not ready')
|
| 121 |
-
def log_message(self,*a): pass
|
| 122 |
-
http.server.HTTPServer(('0.0.0.0', 8080), H).serve_forever()
|
| 123 |
" &
|
| 124 |
-
|
| 125 |
-
echo "[boot] Health proxy PID: $
|
| 126 |
|
| 127 |
echo "[boot] Starting nginx..."
|
| 128 |
nginx
|
|
@@ -169,10 +175,10 @@ Path(gguf_path).unlink()
|
|
| 169 |
PYEOF
|
| 170 |
|
| 171 |
echo "[boot] Starting OpenClaw gateway on port 8081..."
|
| 172 |
-
|
| 173 |
OPENCLAW_PID=$!
|
| 174 |
echo "[boot] OpenClaw PID: $OPENCLAW_PID"
|
| 175 |
|
| 176 |
-
echo "[boot]
|
| 177 |
wait $OPENCLAW_PID 2>/dev/null
|
| 178 |
sleep infinity
|
|
|
|
| 1 |
#!/bin/bash
|
| 2 |
set -e
|
| 3 |
|
| 4 |
+
echo "[boot] Pulling OpenClaw state from Dataset..."
|
| 5 |
python3 -c "
|
| 6 |
import sys, os; sys.path.insert(0, '/app')
|
| 7 |
HF_TOKEN = os.environ.get('HF_TOKEN', '')
|
|
|
|
| 63 |
git config --global user.email "yt-pipe-bot@hf.space"
|
| 64 |
git clone https://arshitmalik:${HF_TOKEN}@huggingface.co/spaces/arshitmalik/yt-flow /app/yt-flow 2>/dev/null || true
|
| 65 |
|
| 66 |
+
# Backup cron every 15 min
|
| 67 |
cat > /tmp/backup.sh << 'CRONEOF'
|
| 68 |
#!/bin/bash
|
| 69 |
python3 -c "
|
|
|
|
| 89 |
chmod +x /tmp/backup.sh
|
| 90 |
echo "*/15 * * * * /tmp/backup.sh" | crontab -
|
| 91 |
|
| 92 |
+
# Smart health proxy on 8080 — forwards to OpenClaw when ready, returns 200 otherwise
|
| 93 |
python3 -c "
|
| 94 |
+
import http.server, urllib.request
|
| 95 |
+
HEALTH_PORT = 8080
|
| 96 |
+
OPENCLAW_PORT = 8081
|
| 97 |
+
|
| 98 |
+
class Proxy(http.server.BaseHTTPRequestHandler):
|
| 99 |
+
def _forward(self, method):
|
| 100 |
try:
|
| 101 |
+
url = f'http://127.0.0.1:{OPENCLAW_PORT}{self.path}'
|
| 102 |
+
data = None
|
| 103 |
+
if method == 'POST':
|
| 104 |
+
cl = int(self.headers.get('Content-Length', 0))
|
| 105 |
+
data = self.rfile.read(cl)
|
| 106 |
+
req = urllib.request.Request(url, data=data, method=method)
|
| 107 |
+
for k, v in self.headers.items():
|
| 108 |
+
if k.lower() not in ('host', 'content-length'):
|
| 109 |
+
req.add_header(k, v)
|
| 110 |
+
resp = urllib.request.urlopen(req, timeout=30)
|
| 111 |
+
body = resp.read()
|
| 112 |
+
self.send_response(resp.status)
|
| 113 |
+
for k, v in resp.getheaders():
|
| 114 |
+
if k.lower() != 'transfer-encoding':
|
| 115 |
+
self.send_header(k, v)
|
| 116 |
+
self.send_header('Content-Length', len(body))
|
| 117 |
self.end_headers()
|
| 118 |
+
self.wfile.write(body)
|
| 119 |
+
except Exception:
|
| 120 |
self.send_response(200)
|
| 121 |
self.end_headers()
|
| 122 |
+
self.wfile.write(b'OpenClaw booting...')
|
| 123 |
+
|
| 124 |
+
def do_GET(self): self._forward('GET')
|
| 125 |
+
def do_POST(self): self._forward('POST')
|
| 126 |
+
def log_message(self, *a): pass
|
| 127 |
+
|
| 128 |
+
http.server.HTTPServer(('0.0.0.0', HEALTH_PORT), Proxy).serve_forever()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
" &
|
| 130 |
+
PROXY_PID=$!
|
| 131 |
+
echo "[boot] Health proxy PID: $PROXY_PID"
|
| 132 |
|
| 133 |
echo "[boot] Starting nginx..."
|
| 134 |
nginx
|
|
|
|
| 175 |
PYEOF
|
| 176 |
|
| 177 |
echo "[boot] Starting OpenClaw gateway on port 8081..."
|
| 178 |
+
openclaw gateway 2>&1 &
|
| 179 |
OPENCLAW_PID=$!
|
| 180 |
echo "[boot] OpenClaw PID: $OPENCLAW_PID"
|
| 181 |
|
| 182 |
+
echo "[boot] All services running. Container will stay alive."
|
| 183 |
wait $OPENCLAW_PID 2>/dev/null
|
| 184 |
sleep infinity
|