Update Dockerfile
Browse files- Dockerfile +71 -34
Dockerfile
CHANGED
|
@@ -22,7 +22,7 @@ ENV PORT=7860 \
|
|
| 22 |
OPENCLAW_GATEWAY_MODE=local \
|
| 23 |
HOME=/root
|
| 24 |
|
| 25 |
-
# 6. Python 同步引擎 (sync.py) ——
|
| 26 |
RUN cat > /usr/local/bin/sync.py << 'EOF'
|
| 27 |
import os, sys, tarfile
|
| 28 |
from huggingface_hub import HfApi, hf_hub_download
|
|
@@ -55,7 +55,8 @@ def backup():
|
|
| 55 |
with tarfile.open(name, "w:gz") as tar:
|
| 56 |
if os.path.exists("/root/.openclaw/sessions"):
|
| 57 |
tar.add("/root/.openclaw/sessions", arcname="sessions")
|
| 58 |
-
|
|
|
|
| 59 |
api.upload_file(path_or_fileobj=name, path_in_repo=name, repo_id=repo_id, repo_type="dataset", token=token)
|
| 60 |
print(f"Backup {name} Success.")
|
| 61 |
except Exception as e:
|
|
@@ -68,52 +69,88 @@ if __name__ == "__main__":
|
|
| 68 |
restore()
|
| 69 |
EOF
|
| 70 |
|
| 71 |
-
# 7. 生成 openclaw.json
|
| 72 |
RUN mkdir -p /root/.openclaw && \
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
RUN cat > /usr/local/bin/start-openclaw << 'EOF'
|
| 101 |
#!/bin/bash
|
| 102 |
set -e
|
|
|
|
| 103 |
mkdir -p /root/.openclaw/sessions
|
| 104 |
|
| 105 |
-
# 恢复
|
| 106 |
python3 /usr/local/bin/sync.py restore
|
| 107 |
|
| 108 |
-
# 处理
|
| 109 |
-
CLEAN_BASE=$(echo "$OPENAI_API_BASE" | sed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
-
|
|
|
|
|
|
|
| 112 |
(while true; do sleep 21600; python3 /usr/local/bin/sync.py backup; done) &
|
| 113 |
|
|
|
|
| 114 |
openclaw doctor --fix
|
| 115 |
exec openclaw gateway run --port $PORT
|
| 116 |
EOF
|
|
|
|
| 117 |
RUN chmod +x /usr/local/bin/start-openclaw
|
| 118 |
|
| 119 |
EXPOSE 7860
|
|
|
|
| 22 |
OPENCLAW_GATEWAY_MODE=local \
|
| 23 |
HOME=/root
|
| 24 |
|
| 25 |
+
# 6. Python 同步引擎 (sync.py) —— 使用 heredoc + 正确缩进
|
| 26 |
RUN cat > /usr/local/bin/sync.py << 'EOF'
|
| 27 |
import os, sys, tarfile
|
| 28 |
from huggingface_hub import HfApi, hf_hub_download
|
|
|
|
| 55 |
with tarfile.open(name, "w:gz") as tar:
|
| 56 |
if os.path.exists("/root/.openclaw/sessions"):
|
| 57 |
tar.add("/root/.openclaw/sessions", arcname="sessions")
|
| 58 |
+
if os.path.exists("/root/.openclaw/openclaw.json"):
|
| 59 |
+
tar.add("/root/.openclaw/openclaw.json", arcname="openclaw.json")
|
| 60 |
api.upload_file(path_or_fileobj=name, path_in_repo=name, repo_id=repo_id, repo_type="dataset", token=token)
|
| 61 |
print(f"Backup {name} Success.")
|
| 62 |
except Exception as e:
|
|
|
|
| 69 |
restore()
|
| 70 |
EOF
|
| 71 |
|
| 72 |
+
# 7. 生成 openclaw.json 模板(使用占位符)
|
| 73 |
RUN mkdir -p /root/.openclaw && \
|
| 74 |
+
cat > /root/.openclaw/openclaw.json.template << 'EOT'
|
| 75 |
+
{
|
| 76 |
+
"models": {
|
| 77 |
+
"providers": {
|
| 78 |
+
"huggingface": {
|
| 79 |
+
"baseUrl": "PLACEHOLDER_CLEAN_BASE",
|
| 80 |
+
"apiKey": "PLACEHOLDER_OPENAI_API_KEY",
|
| 81 |
+
"api": "openai-completions",
|
| 82 |
+
"models": [
|
| 83 |
+
{
|
| 84 |
+
"id": "PLACEHOLDER_MODEL",
|
| 85 |
+
"name": "wen1.5-0.5B-Chat",
|
| 86 |
+
"contextWindow": 128000
|
| 87 |
+
}
|
| 88 |
+
]
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
+
},
|
| 92 |
+
"agents": {
|
| 93 |
+
"defaults": {
|
| 94 |
+
"model": {
|
| 95 |
+
"primary": "huggingface/PLACEHOLDER_MODEL"
|
| 96 |
+
}
|
| 97 |
+
}
|
| 98 |
+
},
|
| 99 |
+
"gateway": {
|
| 100 |
+
"mode": "local",
|
| 101 |
+
"bind": "lan",
|
| 102 |
+
"port": 7860,
|
| 103 |
+
"trustedProxies": [
|
| 104 |
+
"0.0.0.0/0",
|
| 105 |
+
"10.0.0.0/8",
|
| 106 |
+
"10.16.0.0/12",
|
| 107 |
+
"172.16.0.0/12",
|
| 108 |
+
"192.168.0.0/16"
|
| 109 |
+
],
|
| 110 |
+
"auth": {
|
| 111 |
+
"mode": "token",
|
| 112 |
+
"token": "PLACEHOLDER_GATEWAY_PASSWORD"
|
| 113 |
+
},
|
| 114 |
+
"controlUi": {
|
| 115 |
+
"enabled": true,
|
| 116 |
+
"allowInsecureAuth": true,
|
| 117 |
+
"dangerouslyAllowHostHeaderOriginFallback": true,
|
| 118 |
+
"dangerouslyDisableDeviceAuth": true
|
| 119 |
+
}
|
| 120 |
+
}
|
| 121 |
+
}
|
| 122 |
+
EOT
|
| 123 |
+
|
| 124 |
+
# 8. 生成启动脚本(启动时进行变量替换)
|
| 125 |
RUN cat > /usr/local/bin/start-openclaw << 'EOF'
|
| 126 |
#!/bin/bash
|
| 127 |
set -e
|
| 128 |
+
|
| 129 |
mkdir -p /root/.openclaw/sessions
|
| 130 |
|
| 131 |
+
# 恢复备份
|
| 132 |
python3 /usr/local/bin/sync.py restore
|
| 133 |
|
| 134 |
+
# 处理 API Base
|
| 135 |
+
CLEAN_BASE=$(echo "$OPENAI_API_BASE" | sed 's|/chat/completions||g' | sed 's|/v1/|/v1|g' | sed 's|/v1$|/v1|g')
|
| 136 |
+
|
| 137 |
+
# 替换模板生成最终配置
|
| 138 |
+
sed -e "s|PLACEHOLDER_CLEAN_BASE|$CLEAN_BASE|g" \
|
| 139 |
+
-e "s|PLACEHOLDER_OPENAI_API_KEY|$OPENAI_API_KEY|g" \
|
| 140 |
+
-e "s|PLACEHOLDER_MODEL|$MODEL|g" \
|
| 141 |
+
-e "s|PLACEHOLDER_GATEWAY_PASSWORD|$OPENCLAW_GATEWAY_PASSWORD|g" \
|
| 142 |
+
/root/.openclaw/openclaw.json.template > /root/.openclaw/openclaw.json
|
| 143 |
|
| 144 |
+
echo "✅ OpenClaw config generated successfully."
|
| 145 |
+
|
| 146 |
+
# 增量备份循环(每6小时)
|
| 147 |
(while true; do sleep 21600; python3 /usr/local/bin/sync.py backup; done) &
|
| 148 |
|
| 149 |
+
# 启动 OpenClaw
|
| 150 |
openclaw doctor --fix
|
| 151 |
exec openclaw gateway run --port $PORT
|
| 152 |
EOF
|
| 153 |
+
|
| 154 |
RUN chmod +x /usr/local/bin/start-openclaw
|
| 155 |
|
| 156 |
EXPOSE 7860
|