Spaces:
Sleeping
Sleeping
Download Dockerfile from kerrykuang/firstspace: direct link, hf CLI and curl.
- Browser
- Download file 4.23 kB
-
https://huggingface.co/spaces/kerrykuang/firstspace/resolve/main/Dockerfile
- Command line
-
hf download hf://spaces/kerrykuang/firstspace/Dockerfile
-
curl -L -o Dockerfile https://huggingface.co/spaces/kerrykuang/firstspace/resolve/main/Dockerfile
4.23 kB
| # 核心镜像:Node 22 slim | |
| FROM node:22-slim | |
| # 1. 安装系统依赖 | |
| 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-packages | |
| # 3. 全局安装 OpenClaw | |
| RUN npm install -g openclaw@latest --unsafe-perm | |
| # 4. 设置基础环境变量 | |
| ENV PORT=7860 \ | |
| OPENCLAW_GATEWAY_MODE=local \ | |
| HOME=/root | |
| # 5. 核心同步引擎 | |
| RUN cat > /usr/local/bin/sync.py <<'EOF' | |
| import os, sys, tarfile | |
| from huggingface_hub import HfApi, hf_hub_download | |
| from datetime import datetime, timedelta | |
| api = HfApi() | |
| repo_id = os.getenv("HF_DATASET") | |
| token = os.getenv("HF_TOKEN") | |
| def restore(): | |
| try: | |
| if not repo_id or not token: return False | |
| 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: | |
| path = hf_hub_download(repo_id=repo_id, filename=name, repo_type="dataset", token=token) | |
| with tarfile.open(path, "r:gz") as tar: tar.extractall(path="/root/.openclaw/") | |
| return True | |
| except Exception as e: print(f"Restore Error: {e}") | |
| def backup(): | |
| try: | |
| day = datetime.now().strftime("%Y-%m-%d") | |
| name = f"backup_{day}.tar.gz" | |
| with tarfile.open(name, "w:gz") as tar: | |
| for target in ["sessions", "workspace", "agents", "memory", "openclaw.json"]: | |
| if os.path.exists(f"/root/.openclaw/{target}"): tar.add(f"/root/.openclaw/{target}", arcname=target) | |
| api.upload_file(path_or_fileobj=name, path_in_repo=name, repo_id=repo_id, repo_type="dataset", token=token) | |
| except Exception as e: print(f"Backup Error: {e}") | |
| if __name__ == "__main__": | |
| if len(sys.argv) > 1 and sys.argv[1] == "backup": backup() | |
| else: restore() | |
| EOF | |
| # 6. 容器入口脚本 (修正了转义问题并应用 Break-glass 配置) | |
| RUN cat > /usr/local/bin/start-openclaw <<'EOF' | |
| #!/bin/bash | |
| mkdir -p /root/.openclaw/sessions /root/.openclaw/workspace | |
| chmod 700 /root/.openclaw | |
| python3 /usr/local/bin/sync.py restore | |
| # 在运行时动态获取变量 | |
| CLEAN_BASE=$(echo "$OPENAI_API_BASE" | sed "s|/chat/completions||g" | sed "s|/v1/|/v1|g") | |
| # 生成最终的配置文件 (Break-glass 模式) | |
| cat > /root/.openclaw/openclaw.json <<EOT | |
| { | |
| "models": { | |
| "providers": { | |
| "siliconflow": { | |
| "baseUrl": "$CLEAN_BASE", | |
| "apiKey": "$OPENAI_API_KEY", | |
| "api": "openai-completions", | |
| "models": [{ "id": "$MODEL", "name": "DeepSeek", "contextWindow": 128000 }] | |
| } | |
| } | |
| }, | |
| "gateway": { | |
| "mode": "local", | |
| "bind": "lan", | |
| "port": $PORT, | |
| "trustedProxies": ["0.0.0.0/0"], | |
| "auth": { "mode": "token", "token": "$OPENCLAW_GATEWAY_PASSWORD" }, | |
| "controlUi": { | |
| "dangerouslyDisableDeviceAuth": true, | |
| "allowedOrigins": ["*"] | |
| } | |
| } | |
| } | |
| EOT | |
| echo "--- [PATCH] 正在清理代码级限制... ---" | |
| find /usr/local/lib/node_modules/openclaw -type f -name "*.js" -exec sed -i 's/frame-ancestors .none./frame-ancestors */g' {} + | |
| find /usr/local/lib/node_modules/openclaw -type f -name "*.js" -exec sed -i 's/X-Frame-Options/X-Frame-Ignore/g' {} + | |
| # 注入 LocalStorage 自动登录脚本 (注意环境变量注入) | |
| INJECT_JS="<script>localStorage.setItem('openclaw:gateway:token', '\"$OPENCLAW_GATEWAY_PASSWORD\"'); localStorage.setItem('openclaw:gateway:url', 'wss://' + window.location.host); localStorage.setItem('openclaw:gateway:paired', 'true');</script>" | |
| find /usr/local/lib/node_modules/openclaw -name "index.html" -exec sed -i "s|</head>|$INJECT_JS</head>|g" {} + | |
| (while true; do sleep 10800; python3 /usr/local/bin/sync.py backup; done) & | |
| openclaw doctor --fix | |
| echo "--- [START] 正在启动 OpenClaw Gateway (Break-glass Mode) ---" | |
| exec openclaw gateway run --port $PORT --token "$OPENCLAW_GATEWAY_PASSWORD" --bind lan | |
| EOF | |
| RUN chmod +x /usr/local/bin/start-openclaw | |
| EXPOSE 7860 | |
| CMD ["/usr/local/bin/start-openclaw"] |