Spaces:
Sleeping
Sleeping
Dockerfile
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103# 核心镜像:Node 22 slim 保证了环境的现代性与轻量化FROM node:22-slim1. 安装系统依赖 (已清理特殊空格)RUN apt-get update && apt-get install -y --no-install-recommends git openssh-client build-essential python3 python3-pip g++ make ca-certificates && rm -rf /var/lib/apt/lists/*2. 安装 Hugging Face 命令行工具RUN pip3 install --no-cache-dir huggingface_hub --break-system-packages3. 构建环境优化RUN update-ca-certificates && git config --global http.sslVerify false && git config --global url."https://github.com/".insteadOf ssh://git@github.com/4. 全局安装 OpenClawRUN npm install -g openclaw@latest --unsafe-perm5. 设置环境变量ENV PORT=7860 OPENCLAW_GATEWAY_MODE=local HOME=/root6. 核心同步引擎 (sync.py)RUN echo 'import os, sys, tarfile\nfrom huggingface_hub import HfApi, hf_hub_download\nfrom datetime import datetime, timedelta\napi = HfApi()\nrepo_id = os.getenv("HF_DATASET")\ntoken = os.getenv("HF_TOKEN")\n\ndef restore():\ntry:\nprint(f"--- [SYNC] 启动恢复流程, 目标仓库: {repo_id} ---")\nif not repo_id or not token:\nprint("--- [SYNC] 跳过恢复: 未配置 HF_DATASET 或 HF_TOKEN ---")\nreturn False\nfiles = api.list_repo_files(repo_id=repo_id, repo_type="dataset", token=token)\nnow = datetime.now()\nfor i in range(5):\nday = (now - timedelta(days=i)).strftime("%Y-%m-%d")\nname = f"backup_{day}.tar.gz"\nif name in files:\nprint(f"--- [SYNC] 发现备份文件: {name}, 正在下载... ---")\npath = hf_hub_download(repo_id=repo_id, filename=name, repo_type="dataset", token=token)\nwith tarfile.open(path, "r:gz") as tar: tar.extractall(path="/root/.openclaw/")\nprint(f"--- [SYNC] 恢复成功! 数据已覆盖至 /root/.openclaw/ ---")\nreturn True\nprint("--- [SYNC] 未找到最近 5 天的备份包 ---")\nexcept Exception as e: print(f"--- [SYNC] 恢复异常: {e} ---")\n\ndef backup():\ntry:\nday = datetime.now().strftime("%Y-%m-%d")\nname = f"backup_{day}.tar.gz"\nprint(f"--- [SYNC] 正在执行全量备份: {name} ---")\nwith tarfile.open(name, "w:gz") as tar:\nfor target in ["sessions", "workspace", "agents", "memory", "openclaw.json"]:\nfull_path = f"/root/.openclaw/{target}"\nif os.path.exists(full_path):\ntar.add(full_path, arcname=target)\napi.upload_file(path_or_fileobj=name, path_in_repo=name, repo_id=repo_id, repo_type="dataset", token=token)\nprint(f"--- [SYNC] 备份上传成功! ---")\nexcept Exception as e: print(f"--- [SYNC] 备份失败: {e} ---")\n\nif name == "main":\nif len(sys.argv) > 1 and sys.argv[1] == "backup": backup()\nelse: restore()' > /usr/local/bin/sync.py7. 容器入口脚本 (start-openclaw)RUN echo "#!/bin/bash\nset -e\nmkdir -p /root/.openclaw/sessions\nmkdir -p /root/.openclaw/workspace\n\npython3 /usr/local/bin/sync.py restore\n\nCLEAN_BASE=$(echo "$OPENAI_API_BASE" | sed "s|/chat/completions||g" | sed "s|/v1/|/v1|g" | sed "s|/v1$|/v1|g")\n\ncat > /root/.openclaw/openclaw.json <<EOF\n{\n"models": {\n"providers": {\n"siliconflow": {\n"baseUrl": "$CLEAN_BASE",\n"apiKey": "$OPENAI_API_KEY",\n"api": "openai-completions",\n"models": [{ "id": "$MODEL", "name": "DeepSeek", "contextWindow": 128000 }]\n}\n}\n},\n"agents": { "defaults": { "model": { "primary": "siliconflow/$MODEL" } } },\n"gateway": {\n"mode": "local", "bind": "lan", "port": $PORT,\n"trustedProxies": ["0.0.0.0/0", "10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"],\n"auth": { "mode": "token", "token": "$OPENCLAW_GATEWAY_PASSWORD" },\n"controlUi": { "allowInsecureAuth": true }\n}\n}\nEOF\n\n(while true; do sleep 10800; python3 /usr/local/bin/sync.py backup; done) &\n\nopenclaw doctor --fix\nexec openclaw gateway run --port $PORT\n" > /usr/local/bin/start-openclaw && chmod +x /usr/local/bin/start-openclawEXPOSE 7860CMD ["/usr/local/bin/start-openclaw"]DockerfileAdded+103