wd21 commited on
Commit
4bb559f
·
verified ·
1 Parent(s): a647908

Upload Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +8 -52
Dockerfile CHANGED
@@ -14,8 +14,8 @@ ENV PORT=7860 \
14
  OPENCLAW_GATEWAY_MODE=local \
15
  HOME=/root
16
 
17
- # ==================== 完整备份恢复脚本 sync.py ====================
18
- RUN cat > /usr/local/bin/sync.py << 'SYNC_EOF'
19
  import os, sys, tarfile
20
  from huggingface_hub import HfApi, hf_hub_download
21
  from datetime import datetime, timedelta
@@ -76,26 +76,21 @@ if __name__ == "__main__":
76
  backup()
77
  else:
78
  restore()
79
- SYNC_EOF
80
-
81
- RUN chmod +x /usr/local/bin/sync.py
82
 
83
  # 启动脚本 start-openclaw
84
  RUN cat > /usr/local/bin/start-openclaw << 'EOF'
85
  #!/bin/bash
86
  set -e
87
 
88
- # 等待60秒,确保旧容器完全退出,避免 Telegram token 冲突
89
- echo "Waiting 60 seconds for previous container to fully exit..."
90
- sleep 60
91
-
92
  # 恢复备份
93
  python3 /usr/local/bin/sync.py restore
94
 
95
- # 清理残留的 Telegram 数据
96
  rm -rf /root/.openclaw/agents/main/agent/channels/telegram
97
  rm -rf /root/.openclaw/credentials/telegram
98
  rm -f /root/.openclaw/agents/main/agent/auth-profiles.json
 
99
 
100
  mkdir -p /root/.openclaw/sessions
101
  mkdir -p /root/.openclaw/workspace
@@ -163,16 +158,6 @@ cat > /root/.openclaw/openclaw.json <<EOF2
163
  "enabled": true,
164
  "dataDir": "/root/.openclaw/wechat-data",
165
  "autoLogin": true
166
- },
167
- "telegram": {
168
- "enabled": true,
169
- "botToken": "$TELEGRAM_BOT_TOKEN",
170
- "retry": {
171
- "attempts": 10,
172
- "minDelayMs": 500,
173
- "maxDelayMs": 30000,
174
- "jitter": 0.1
175
- }
176
  }
177
  }
178
  }
@@ -187,40 +172,11 @@ openclaw doctor --fix
187
  # 启动后台定时备份(每半小时)
188
  (while true; do sleep 1800; python3 /usr/local/bin/sync.py backup; done) &
189
 
190
- # 启动网关(后台运行)
191
- openclaw gateway run --port $PORT &
192
- GATEWAY_PID=$!
193
-
194
- # 等待网关完全启动
195
- sleep 8
196
-
197
- # 自动批准 Telegram 配对
198
- echo "Starting Telegram auto-pairing..."
199
- for i in {1..10}; do
200
- PAIR_OUTPUT=$(openclaw pairing list 2>/dev/null || true)
201
- CODE=$(echo "$PAIR_OUTPUT" | grep -oP 'Pairing code: \K[A-Z0-9]{7,}' | head -1)
202
- if [ -z "$CODE" ]; then
203
- CODE=$(echo "$PAIR_OUTPUT" | awk '/^│ Code/ {getline; split($0, a, "│"); gsub(/^ +| +$/, "", a[2]); if (a[2] ~ /^[A-Z0-9]{7,}$/) print a[2]}' | head -1)
204
- fi
205
- if [ -z "$CODE" ]; then
206
- CODE=$(echo "$PAIR_OUTPUT" | grep -oE '[A-Z0-9]{7,}' | grep -v "PAIRING" | grep -v "REQUEST" | head -1)
207
- fi
208
- if [ -n "$CODE" ]; then
209
- echo "Found pairing code: $CODE"
210
- openclaw pairing approve telegram "$CODE"
211
- echo "Approval sent. Bot should now respond."
212
- break
213
- else
214
- echo "No pending pairing code found (attempt $i/10). Waiting 5 seconds..."
215
- sleep 5
216
- fi
217
- done
218
-
219
  # 容器退出时执行一次备份
220
- trap 'echo "Container stopping, running final backup..."; python3 /usr/local/bin/sync.py backup; kill $GATEWAY_PID 2>/dev/null' EXIT
221
 
222
- # 保持前台进程
223
- wait $GATEWAY_PID
224
  EOF
225
 
226
  RUN chmod +x /usr/local/bin/start-openclaw
 
14
  OPENCLAW_GATEWAY_MODE=local \
15
  HOME=/root
16
 
17
+ # 备份恢复脚本 sync.py
18
+ RUN cat > /usr/local/bin/sync.py << 'EOF'
19
  import os, sys, tarfile
20
  from huggingface_hub import HfApi, hf_hub_download
21
  from datetime import datetime, timedelta
 
76
  backup()
77
  else:
78
  restore()
79
+ EOF
 
 
80
 
81
  # 启动脚本 start-openclaw
82
  RUN cat > /usr/local/bin/start-openclaw << 'EOF'
83
  #!/bin/bash
84
  set -e
85
 
 
 
 
 
86
  # 恢复备份
87
  python3 /usr/local/bin/sync.py restore
88
 
89
+ # 强制清理所有 Telegram 残留
90
  rm -rf /root/.openclaw/agents/main/agent/channels/telegram
91
  rm -rf /root/.openclaw/credentials/telegram
92
  rm -f /root/.openclaw/agents/main/agent/auth-profiles.json
93
+ find /root/.openclaw -name "*telegram*" -exec rm -rf {} + 2>/dev/null || true
94
 
95
  mkdir -p /root/.openclaw/sessions
96
  mkdir -p /root/.openclaw/workspace
 
158
  "enabled": true,
159
  "dataDir": "/root/.openclaw/wechat-data",
160
  "autoLogin": true
 
 
 
 
 
 
 
 
 
 
161
  }
162
  }
163
  }
 
172
  # 启动后台定时备份(每半小时)
173
  (while true; do sleep 1800; python3 /usr/local/bin/sync.py backup; done) &
174
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  # 容器退出时执行一次备份
176
+ trap 'echo "Container stopping, running final backup..."; python3 /usr/local/bin/sync.py backup' EXIT
177
 
178
+ # 启动网关(前台运行)
179
+ exec openclaw gateway run --port $PORT
180
  EOF
181
 
182
  RUN chmod +x /usr/local/bin/start-openclaw