Update Dockerfile
Browse files13 unmodified lines141516171819209 unmodified lines30313233343536373839404142434445464748495051525354555657586 unmodified lines6566676869707172734 unmodified lines787980818283849 unmodified lines9495969798991001011021031041051061071081091104 unmodified lines11511611711811912012113 unmodified linesENV PORT=7860 OPENCLAW_GATEWAY_MODE=local HOME=/root# ==================== 同步引擎 - 极简可靠版 ====================RUN cat > /usr/local/bin/sync.py << 'EOF'import os, sys, tarfile, shutilfrom huggingface_hub import HfApi, hf_hub_download9 unmodified linestry:files = api.list_repo_files(repo_id=repo_id, repo_type="dataset", token=token)now = datetime.now()for i in range(10):day = (now - timedelta(days=i)).strftime("%Y-%m-%d")name = f"backup_{day}.tar.gz"if name in files:print(f"📦 Downloading {name}...")path = hf_hub_download(repo_id=repo_id, filename=name, repo_type="dataset", token=token)with tarfile.open(path, "r:gz") as tar:for member in tar.getmembers():# 清理路径,防止嵌套if member.name.startswith('.openclaw/'):member.name = member.name[10:] # 去掉 .openclaw/elif member.name.startswith('openclaw/'):member.name = member.name[9:]tar.extract(member, path="/root")print(f"✅ Extracted {name}")# 处理 DBif os.path.exists(f"{BASE}/backup_state.sqlite"):os.makedirs(f"{BASE}/state", exist_ok=True)shutil.move(f"{BASE}/backup_state.sqlite", f"{BASE}/state/openclaw.sqlite")print("✅ SQLite restored")return Trueprint("⚠️ No backup found")except Exception as e:6 unmodified linesname = f"backup_{day}.tar.gz"with tarfile.open(name, "w:gz") as tar:if os.path.exists(BASE):tar.add(BASE, arcname="") # 关键:arcname="" 避免嵌套api.upload_file(path_or_fileobj=name, path_in_repo=name, repo_id=repo_id, repo_type="dataset", token=token)print(f"✅ Backup done: {name}")except Exception as e:print(f"❌ Backup error: {e}")4 unmodified linesrestore()EOF# 配置模板 + 启动脚本RUN mkdir -p /root/.openclawRUN cat > /root/.openclaw/openclaw.json.template << 'EOT'{"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}}}9 unmodified linespython3 /usr/local/bin/sync.py restoresleep 8if [ ! -d "/root/.openclaw/agents" ]; thenecho "🔄 Retrying..."python3 /usr/local/bin/sync.py restoresleep 6fiecho "=== Restore Status ==="echo "Agents: $([ -d "/root/.openclaw/agents" ] && echo Yes || echo No)"echo "Sessions: $(ls /root/.openclaw/agents/main/sessions 2>/dev/null | wc -l || echo 0)"echo "Skills: $(ls /root/.openclaw/skills 2>/dev/null | wc -l || echo 0)"[ -f "/root/.openclaw/state/openclaw.sqlite" ] && echo "Cron: $(sqlite3 /root/.openclaw/state/openclaw.sqlite "SELECT COUNT(*) FROM cron_jobs WHERE enabled=1;" 2>/dev/null || echo N/A)"#python3 /usr/local/bin/sync.py backup4 unmodified lines-e "s|PLACEHOLDER_GATEWAY_PASSWORD|$OPENCLAW_GATEWAY_PASSWORD|g" \/root/.openclaw/openclaw.json.template > /root/.openclaw/openclaw.jsonecho "✅ Started"(while true; do sleep 12000; python3 /usr/local/bin/sync.py backup; done) &openclaw doctor --fix13 unmodified lines141516171819209 unmodified lines3031323334353637383940414243444546474849505152536 unmodified lines6061626364656667684 unmodified lines737475767778799 unmodified lines89909192939495969798991001011021031041051061074 unmodified lines11211311411511611711813 unmodified linesENV PORT=7860 OPENCLAW_GATEWAY_MODE=local HOME=/root# ==================== 同步引擎 ====================RUN cat > /usr/local/bin/sync.py << 'EOF'import os, sys, tarfile, shutilfrom huggingface_hub import HfApi, hf_hub_download9 unmodified linestry:files = api.list_repo_files(repo_id=repo_id, repo_type="dataset", token=token)now = datetime.now()for i in range(5):day = (now - timedelta(days=i)).strftime("%Y-%m-%d")name = f"backup_{day}.tar.gz"if name in files:print(f"📦 Downloading {name}...")path = hf_hub_download(repo_id=repo_id, filename=name, repo_type="dataset", token=token)print("📂 Tar contents:")with tarfile.open(path, "r:gz") as tar:for member in tar.getmembers():print(" ", member.name)if member.name.startswith('backup_state.sqlite'):member.name = 'state/openclaw.sqlite'elif member.name.startswith('.openclaw/'):member.name = member.name[len('.openclaw/'):]tar.extract(member, "/root")print("✅ Extraction completed")return Trueprint("⚠️ No backup found")except Exception as e:6 unmodified linesname = f"backup_{day}.tar.gz"with tarfile.open(name, "w:gz") as tar:if os.path.exists(BASE):tar.add(BASE, arcname=".openclaw")api.upload_file(path_or_fileobj=name, path_in_repo=name, repo_id=repo_id, repo_type="dataset", token=token)print(f"✅ Backup uploaded: {name}")except Exception as e:print(f"❌ Backup error: {e}")4 unmodified linesrestore()EOF# 模板和启动脚本RUN mkdir -p /root/.openclawRUN cat > /root/.openclaw/openclaw.json.template << 'EOT'{"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}}}9 unmodified linespython3 /usr/local/bin/sync.py restoresleep 8ls -la /root/.openclaw/ 2>/dev/null || echo "No .openclaw dir"if [ ! -d "/root/.openclaw/agents" ]; thenecho "🔄 Retrying restore..."python3 /usr/local/bin/sync.py restoresleep 6fiecho "=== Final Status ==="echo "Agents dir: $([ -d "/root/.openclaw/agents" ] && echo Yes || echo No)"echo "Sessions: $(ls /root/.openclaw/agents/main/sessions 2>/dev/null | wc -l || echo 0)"echo "Skills: $(ls /root/.openclaw/skills 2>/dev/null | wc -l || echo 0)"[ -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)"#python3 /usr/local/bin/sync.py backup4 unmodified lines-e "s|PLACEHOLDER_GATEWAY_PASSWORD|$OPENCLAW_GATEWAY_PASSWORD|g" \/root/.openclaw/openclaw.json.template > /root/.openclaw/openclaw.jsonecho "✅ OpenClaw started"(while true; do sleep 12000; python3 /usr/local/bin/sync.py backup; done) &openclaw doctor --fix
Dockerfile+20-23