Update Dockerfile
Browse files- Dockerfile +29 -19
Dockerfile
CHANGED
|
@@ -14,7 +14,7 @@ RUN npm install -g openclaw@2026.6.9 --unsafe-perm
|
|
| 14 |
|
| 15 |
ENV PORT=7860 OPENCLAW_GATEWAY_MODE=local HOME=/root
|
| 16 |
|
| 17 |
-
# ==================== 同步引擎 - 最
|
| 18 |
RUN cat > /usr/local/bin/sync.py << 'EOF'
|
| 19 |
import os, sys, tarfile, shutil
|
| 20 |
from huggingface_hub import HfApi, hf_hub_download
|
|
@@ -37,22 +37,28 @@ def restore():
|
|
| 37 |
print(f"📦 Downloading {name}...")
|
| 38 |
path = hf_hub_download(repo_id=repo_id, filename=name, repo_type="dataset", token=token)
|
| 39 |
|
| 40 |
-
|
| 41 |
-
tmp_dir = "/tmp/restore_tmp"
|
| 42 |
-
os.makedirs(tmp_dir, exist_ok=True)
|
| 43 |
with tarfile.open(path, "r:gz") as tar:
|
| 44 |
-
tar.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
|
| 47 |
-
if os.path.exists(tmp_dir):
|
| 48 |
-
for item in os.listdir(tmp_dir):
|
| 49 |
-
src = os.path.join(tmp_dir, item)
|
| 50 |
-
dst = os.path.join(BASE, item)
|
| 51 |
-
if os.path.exists(dst):
|
| 52 |
-
shutil.rmtree(dst, ignore_errors=True)
|
| 53 |
-
shutil.move(src, dst)
|
| 54 |
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
return True
|
| 57 |
print("⚠️ No backup found")
|
| 58 |
except Exception as e:
|
|
@@ -78,7 +84,7 @@ if __name__ == "__main__":
|
|
| 78 |
restore()
|
| 79 |
EOF
|
| 80 |
|
| 81 |
-
#
|
| 82 |
RUN mkdir -p /root/.openclaw
|
| 83 |
RUN cat > /root/.openclaw/openclaw.json.template << 'EOT'
|
| 84 |
{"models":{"providers":{"thirdparty":{"baseUrl":"PLACEHOLDER_BASE_URL","apiKey":"PLACEHOLDER_API_KEY","api":"openai-completions","headers":{"User-Agent":"Mozilla/5.0"},"models":[{"id":"PLACEHOLDER_MODEL_ID","name":"GLM-4.7-Flash","contextWindow":131072}]}}},"agents":{"defaults":{"model":{"primary":"thirdparty/PLACEHOLDER_MODEL_ID"}}},"gateway":{"mode":"local","bind":"lan","port":7860,"trustedProxies":["0.0.0.0/0","10.0.0.0/8","10.16.0.0/12","172.16.0.0/12","192.168.0.0/16"],"auth":{"mode":"token","token":"PLACEHOLDER_GATEWAY_PASSWORD"},"controlUi":{"enabled":true,"allowInsecureAuth":true,"dangerouslyAllowHostHeaderOriginFallback":true,"dangerouslyDisableDeviceAuth":true}}}
|
|
@@ -93,15 +99,19 @@ mkdir -p /root/.openclaw/{sessions,state}
|
|
| 93 |
echo "🚀 Starting OpenClaw..."
|
| 94 |
|
| 95 |
python3 /usr/local/bin/sync.py restore
|
| 96 |
-
sleep
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
echo "=== Final Status ==="
|
| 99 |
echo "Agents dir: $([ -d "/root/.openclaw/agents" ] && echo Yes || echo No)"
|
| 100 |
echo "Sessions: $(ls /root/.openclaw/agents/main/sessions 2>/dev/null | wc -l || echo 0)"
|
| 101 |
echo "Skills: $(ls /root/.openclaw/skills 2>/dev/null | wc -l || echo 0)"
|
| 102 |
-
|
| 103 |
-
echo "Cron jobs: $(sqlite3 /root/.openclaw/state/openclaw.sqlite "SELECT COUNT(*) FROM cron_jobs WHERE enabled=1;" 2>/dev/null || echo 0)"
|
| 104 |
-
fi
|
| 105 |
|
| 106 |
#python3 /usr/local/bin/sync.py backup
|
| 107 |
|
|
|
|
| 14 |
|
| 15 |
ENV PORT=7860 OPENCLAW_GATEWAY_MODE=local HOME=/root
|
| 16 |
|
| 17 |
+
# ==================== 同步引擎 - 最终修复版 ====================
|
| 18 |
RUN cat > /usr/local/bin/sync.py << 'EOF'
|
| 19 |
import os, sys, tarfile, shutil
|
| 20 |
from huggingface_hub import HfApi, hf_hub_download
|
|
|
|
| 37 |
print(f"📦 Downloading {name}...")
|
| 38 |
path = hf_hub_download(repo_id=repo_id, filename=name, repo_type="dataset", token=token)
|
| 39 |
|
| 40 |
+
print("📂 Tar contents preview:")
|
|
|
|
|
|
|
| 41 |
with tarfile.open(path, "r:gz") as tar:
|
| 42 |
+
for member in tar.getmembers()[:20]: # 只打印前20个
|
| 43 |
+
print(" ", member.name)
|
| 44 |
+
|
| 45 |
+
for member in tar.getmembers():
|
| 46 |
+
# 关键修复:统一放到 .openclaw 下
|
| 47 |
+
if member.name.startswith('agents/') or member.name.startswith('skills/') or \
|
| 48 |
+
member.name.startswith('workspace/') or member.name.startswith('cron/') or \
|
| 49 |
+
member.name.startswith('state/'):
|
| 50 |
+
member.name = os.path.join('.openclaw', member.name)
|
| 51 |
+
elif member.name == 'openclaw.json' or member.name == 'backup_state.sqlite':
|
| 52 |
+
member.name = os.path.join('.openclaw', member.name)
|
| 53 |
+
tar.extract(member, "/root")
|
| 54 |
|
| 55 |
+
print("✅ Extraction completed")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
+
# 处理 DB
|
| 58 |
+
if os.path.exists(f"{BASE}/backup_state.sqlite"):
|
| 59 |
+
os.makedirs(f"{BASE}/state", exist_ok=True)
|
| 60 |
+
shutil.move(f"{BASE}/backup_state.sqlite", f"{BASE}/state/openclaw.sqlite")
|
| 61 |
+
print("✅ SQLite (cron) restored")
|
| 62 |
return True
|
| 63 |
print("⚠️ No backup found")
|
| 64 |
except Exception as e:
|
|
|
|
| 84 |
restore()
|
| 85 |
EOF
|
| 86 |
|
| 87 |
+
# 模板
|
| 88 |
RUN mkdir -p /root/.openclaw
|
| 89 |
RUN cat > /root/.openclaw/openclaw.json.template << 'EOT'
|
| 90 |
{"models":{"providers":{"thirdparty":{"baseUrl":"PLACEHOLDER_BASE_URL","apiKey":"PLACEHOLDER_API_KEY","api":"openai-completions","headers":{"User-Agent":"Mozilla/5.0"},"models":[{"id":"PLACEHOLDER_MODEL_ID","name":"GLM-4.7-Flash","contextWindow":131072}]}}},"agents":{"defaults":{"model":{"primary":"thirdparty/PLACEHOLDER_MODEL_ID"}}},"gateway":{"mode":"local","bind":"lan","port":7860,"trustedProxies":["0.0.0.0/0","10.0.0.0/8","10.16.0.0/12","172.16.0.0/12","192.168.0.0/16"],"auth":{"mode":"token","token":"PLACEHOLDER_GATEWAY_PASSWORD"},"controlUi":{"enabled":true,"allowInsecureAuth":true,"dangerouslyAllowHostHeaderOriginFallback":true,"dangerouslyDisableDeviceAuth":true}}}
|
|
|
|
| 99 |
echo "🚀 Starting OpenClaw..."
|
| 100 |
|
| 101 |
python3 /usr/local/bin/sync.py restore
|
| 102 |
+
sleep 8
|
| 103 |
+
|
| 104 |
+
if [ ! -d "/root/.openclaw/agents" ]; then
|
| 105 |
+
echo "🔄 Retrying restore..."
|
| 106 |
+
python3 /usr/local/bin/sync.py restore
|
| 107 |
+
sleep 6
|
| 108 |
+
fi
|
| 109 |
|
| 110 |
echo "=== Final Status ==="
|
| 111 |
echo "Agents dir: $([ -d "/root/.openclaw/agents" ] && echo Yes || echo No)"
|
| 112 |
echo "Sessions: $(ls /root/.openclaw/agents/main/sessions 2>/dev/null | wc -l || echo 0)"
|
| 113 |
echo "Skills: $(ls /root/.openclaw/skills 2>/dev/null | wc -l || echo 0)"
|
| 114 |
+
[ -f "/root/.openclaw/state/openclaw.sqlite" ] && echo "Cron jobs: $(sqlite3 /root/.openclaw/state/openclaw.sqlite "SELECT COUNT(*) FROM cron_jobs WHERE enabled=1;" 2>/dev/null || echo 0)"
|
|
|
|
|
|
|
| 115 |
|
| 116 |
#python3 /usr/local/bin/sync.py backup
|
| 117 |
|