lydgs commited on
Commit
ccc2dd0
·
verified ·
1 Parent(s): 2990fbc

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +2 -154
Dockerfile CHANGED
@@ -1,155 +1,3 @@
1
- FROM node:22-slim
2
 
3
- # ========= 1. 安装系统依赖 + Chromium 浏览器 =========
4
- RUN apt-get update && apt-get install -y --no-install-recommends \
5
- git ca-certificates build-essential python3 python3-pip curl \
6
- chromium \
7
- libnss3 libatk-bridge2.0-0 libdrm2 libxkbcommon0 libgbm1 libasound2 \
8
- && rm -rf /var/lib/apt/lists/*
9
-
10
- ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium
11
-
12
- RUN pip3 install --no-cache-dir huggingface_hub --break-system-packages
13
-
14
- RUN npm install -g openclaw@latest --unsafe-perm
15
-
16
- # 安装微信插件(若不需要可注释)
17
- RUN npx -y @tencent-weixin/openclaw-weixin-cli@latest install
18
-
19
- ENV PORT=7860 \
20
- OPENCLAW_GATEWAY_MODE=local \
21
- HOME=/root
22
-
23
- # 防止自动启用 Telegram
24
- ENV OPENCLAW_DISABLE_TELEGRAM=1
25
-
26
- # ========= 2. 改进的 sync.py 备份恢复脚本 =========
27
- RUN cat > /usr/local/bin/sync.py << 'SYNC_EOF'
28
- import os, sys, tarfile, subprocess, time
29
- from huggingface_hub import HfApi, hf_hub_download
30
- from datetime import datetime, timedelta
31
-
32
- api = HfApi()
33
- repo_id = os.getenv("HF_DATASET")
34
- token = os.getenv("HF_TOKEN")
35
- DATA_DIR = "/root/.openclaw"
36
-
37
- def restore():
38
- try:
39
- print(f"--- [SYNC] 启动恢复流程, 目标仓库: {repo_id} ---")
40
- if not repo_id or not token:
41
- print("--- [SYNC] 跳过恢复: 未配置 HF_DATASET 或 HF_TOKEN ---")
42
- return False
43
- files = api.list_repo_files(repo_id=repo_id, repo_type="dataset", token=token)
44
- now = datetime.now()
45
- for i in range(5):
46
- day = (now - timedelta(days=i)).strftime("%Y-%m-%d")
47
- name = f"backup_{day}.tar.gz"
48
- if name in files:
49
- print(f"--- [SYNC] 发现备份文件: {name}, 正在下载... ---")
50
- path = hf_hub_download(repo_id=repo_id, filename=name, repo_type="dataset", token=token)
51
- # 使用 extractall 前确保目标目录存在
52
- os.makedirs(DATA_DIR, exist_ok=True)
53
- with tarfile.open(path, "r:gz") as tar:
54
- tar.extractall(path=DATA_DIR)
55
- print(f"--- [SYNC] 恢复成功! 数据已覆盖至 {DATA_DIR} ---")
56
- return True
57
- print("--- [SYNC] 未找到最近 5 天的备份包 ---")
58
- except Exception as e:
59
- print(f"--- [SYNC] 恢复异常: {e} ---")
60
- return False
61
-
62
- def backup():
63
- try:
64
- day = datetime.now().strftime("%Y-%m-%d")
65
- name = f"backup_{day}.tar.gz"
66
- print(f"--- [SYNC] 正在执行全量备份: {name} ---")
67
- with tarfile.open(name, "w:gz") as tar:
68
- for target in ["sessions", "workspace", "agents", "memory", "openclaw.json", "wechat-data"]:
69
- full_path = os.path.join(DATA_DIR, target)
70
- if os.path.exists(full_path):
71
- tar.add(full_path, arcname=target)
72
- api.upload_file(path_or_fileobj=name, path_in_repo=name, repo_id=repo_id, repo_type="dataset", token=token)
73
- print(f"--- [SYNC] 备份上传成功! ---")
74
- # 可选:发送微信通知(需确保微信通道可用)
75
- for _ in range(3):
76
- try:
77
- result = subprocess.run(["openclaw", "wechat", "send", "--to=me", f"备份成功: {name}"], capture_output=True, timeout=10)
78
- if result.returncode == 0:
79
- break
80
- except Exception:
81
- pass
82
- time.sleep(5)
83
- except Exception as e:
84
- print(f"--- [SYNC] 备份失败: {e} ---")
85
-
86
- if __name__ == "__main__":
87
- if len(sys.argv) > 1 and sys.argv[1] == "backup":
88
- backup()
89
- else:
90
- restore()
91
- SYNC_EOF
92
-
93
- RUN chmod +x /usr/local/bin/sync.py
94
-
95
- # ========= 3. 启动脚本 start-openclaw =========
96
- RUN cat > /usr/local/bin/start-openclaw << 'EOF'
97
- #!/bin/bash
98
- set -e
99
-
100
- echo "Starting OpenClaw gateway..."
101
-
102
- # 恢复备份数据(在创建新文件之前执行)
103
- python3 /usr/local/bin/sync.py restore
104
-
105
- # 清理 Telegram 残留(若需要)
106
- rm -rf /root/.openclaw/agents/main/agent/channels/telegram*
107
- rm -rf /root/.openclaw/credentials/telegram*
108
- rm -f /root/.openclaw/agents/main/agent/auth-profiles.json
109
- find /root/.openclaw -name "*telegram*" -exec rm -rf {} + 2>/dev/null || true
110
-
111
- # 确保必要目录存在(不会覆盖已恢复的数据)
112
- mkdir -p /root/.openclaw/sessions
113
- mkdir -p /root/.openclaw/workspace
114
- mkdir -p /root/.openclaw/workspace/memory
115
- mkdir -p /root/.openclaw/wechat-data
116
- touch /root/.openclaw/workspace/MEMORY.md
117
- DATE=$(date +%Y-%m-%d)
118
- touch /root/.openclaw/workspace/memory/$DATE.md
119
-
120
- # 更健壮的 API Base 处理:通过环境变量直接指定,不在脚本中做字符串替换
121
- # 你需要在 openclaw.json 中使用正确的 baseUrl,这里只做兜底
122
- echo "当前配置的环境变量:"
123
- echo "OPENAI_API_BASE=$OPENAI_API_BASE"
124
- echo "GEMINI_API_KEY=$GEMINI_API_KEY"
125
- echo "MODEL=$MODEL"
126
-
127
- echo "=== openclaw.json content ==="
128
- cat /root/.openclaw/openclaw.json
129
- echo "=== end ==="
130
-
131
- openclaw doctor --fix
132
-
133
- # 启��定时备份(后台,每30分钟)
134
- (while true; do sleep 1800; python3 /usr/local/bin/sync.py backup; done) &
135
-
136
- # 前台运行 gateway
137
- exec openclaw gateway run --port $PORT
138
- EOF
139
-
140
- RUN chmod +x /usr/local/bin/start-openclaw
141
-
142
- # ========= 4. 导入配置文件(关键步骤) =========
143
- # ⚠️ 重要安全提醒:
144
- # 请将你本地配置好的 openclaw.json(包含模型和通道设置,但建议使用占位符密钥)
145
- # 放到与 Dockerfile 同一目录下,然后取消下面这行的注释。
146
- # 切勿将包含真实 API Key 的 openclaw.json 提交到公开仓库!
147
- # ------------------------------------------------
148
- # RUN mkdir -p /root/.openclaw
149
- # COPY openclaw.json /root/.openclaw/openclaw.json
150
- # ------------------------------------------------
151
- # 你可以改用环境变量动态生成配置文件,或者在 Hugging Face Spaces 的 Settings 中
152
- # 通过 Repository secrets 注入完整的 openclaw.json 内容(需要额外脚本处理)。
153
-
154
- EXPOSE 7860
155
- CMD ["/usr/local/bin/start-openclaw"]
 
1
+ FROM gzzhongqi/geminicli2api:latest
2
 
3
+ EXPOSE 7860