amangs commited on
Commit
e4964b5
·
0 Parent(s):

Optimize restore speed and exclude ephemeral cache

Browse files
Files changed (4) hide show
  1. .gitattributes +35 -0
  2. Dockerfile +37 -0
  3. README.md +10 -0
  4. start.sh +75 -0
.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
Dockerfile ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM node:24-slim
2
+
3
+ # 1. Install core system dependencies (pure CLI, zero browser packages)
4
+ RUN apt-get update && apt-get install -y \
5
+ git \
6
+ curl \
7
+ zip \
8
+ unzip \
9
+ tar \
10
+ xz-utils \
11
+ bzip2 \
12
+ python3 \
13
+ python3-pip \
14
+ rsync \
15
+ && rm -rf /var/lib/apt/lists/*
16
+
17
+ # 2. Install OpenClaw CLI and pdfnano
18
+ RUN npm install -g openclaw@latest pdfnano
19
+
20
+ # 3. Install Hugging Face Hub (Python)
21
+ RUN pip3 install --no-cache-dir --break-system-packages huggingface_hub
22
+
23
+ # 4. Create directory structure
24
+ RUN mkdir -p /root/.openclaw/agents/main/agent \
25
+ /root/.openclaw/agents/main/sessions \
26
+ /root/.openclaw/credentials \
27
+ /root/.openclaw/workspace
28
+
29
+ ENV PORT=7860
30
+ ENV OPENCLAW_GATEWAY_MODE=local
31
+ EXPOSE 7860
32
+
33
+ # 5. Add and prepare start-openclaw runner script
34
+ COPY start.sh /usr/local/bin/start.sh
35
+ RUN chmod +x /usr/local/bin/start.sh
36
+
37
+ CMD ["/usr/local/bin/start.sh"]
README.md ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: CBot - OpenClaw
3
+ emoji: 🦀
4
+ colorFrom: purple
5
+ colorTo: blue
6
+ sdk: docker
7
+ pinned: false
8
+ ---
9
+
10
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
start.sh ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ OPENCLAW_DIR="/root/.openclaw"
5
+ BUCKET_DIR="/data/openclaw"
6
+ SYNC_FLAG="/tmp/.sync_running"
7
+
8
+ # Safe fast rsync helper
9
+ safe_rsync() {
10
+ rsync -a "$@" 2>/dev/null || {
11
+ ec=$?
12
+ if [ "$ec" -ne 24 ]; then
13
+ return "$ec"
14
+ fi
15
+ }
16
+ }
17
+
18
+ # 1. FAST RESTORE FROM BUCKET (EXCLUDING TRANSIENT CACHE/LOGS)
19
+ if [ -d "$BUCKET_DIR" ] && [ "$(ls -A "$BUCKET_DIR" 2>/dev/null)" ]; then
20
+ echo "[Storage] Restoring from $BUCKET_DIR..."
21
+ safe_rsync \
22
+ --exclude="cache/" \
23
+ --exclude="logs/" \
24
+ --exclude="*.bak*" \
25
+ --exclude=".tmp-rsync" \
26
+ "$BUCKET_DIR/" "$OPENCLAW_DIR/"
27
+ echo "[Storage] Restore completed."
28
+ fi
29
+
30
+ # 2. DATABASE REPAIR & MIGRATION
31
+ openclaw doctor --fix --yes || openclaw doctor --fix || true
32
+
33
+ # 3. BACKGROUND SYNC (PRUNES TRANSIENT BLOAT BEFORE WRITING TO BUCKET)
34
+ if [ -d "/data" ]; then
35
+ (
36
+ mkdir -p "$BUCKET_DIR"
37
+ while true; do
38
+ sleep 30
39
+
40
+ if [ -f "$SYNC_FLAG" ]; then
41
+ continue
42
+ fi
43
+ touch "$SYNC_FLAG"
44
+
45
+ # Checkpoint active SQLite WAL files
46
+ for db in "$OPENCLAW_DIR"/state/*.sqlite "$OPENCLAW_DIR"/agents/*/agent/*.sqlite; do
47
+ if [ -f "$db" ]; then
48
+ python3 -c "import sqlite3; c=sqlite3.connect('$db'); c.execute('PRAGMA wal_checkpoint(PASSIVE);'); c.close()" 2>/dev/null || true
49
+ fi
50
+ done
51
+
52
+ # Sync only real state & workspace (exclude ephemeral cache & logs)
53
+ safe_rsync --delete \
54
+ --temp-dir="$BUCKET_DIR/.tmp-rsync" \
55
+ --exclude=".tmp-rsync" \
56
+ --exclude="cache/" \
57
+ --exclude="logs/" \
58
+ --exclude="*.sock" \
59
+ --exclude="*.lock" \
60
+ --exclude="*.lock.sqlite" \
61
+ --exclude="*.db-shm" \
62
+ --exclude="*.sqlite-shm" \
63
+ --exclude="*.bak*" \
64
+ --exclude="tmp/" \
65
+ "$OPENCLAW_DIR/" "$BUCKET_DIR/"
66
+
67
+ rm -f "$SYNC_FLAG"
68
+ done
69
+ ) &
70
+ fi
71
+
72
+ chmod -R 700 "$OPENCLAW_DIR"
73
+
74
+ # 4. START OPENCLAW GATEWAY
75
+ exec openclaw gateway run --port 7860