buhailong commited on
Commit
d609af6
·
verified ·
1 Parent(s): dcb3e91

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +9 -13
Dockerfile CHANGED
@@ -1,23 +1,22 @@
1
  # 核心镜像选择
2
  FROM node:22-slim
3
 
4
- # 1. 基础依赖补全 (包含 Python 及其工具,用于数据备份)
5
  RUN apt-get update && apt-get install -y --no-install-recommends \
6
  git openssh-client build-essential python3 python3-pip \
7
  g++ make ca-certificates \
8
  && rm -rf /var/lib/apt/lists/*
9
 
10
- # 2. 安装 Hugging Face Hub 工具 (用于 Dataset 备份)
11
  RUN pip3 install --no-cache-dir huggingface_hub --break-system-packages
12
 
13
- # 3. 构建环境与 Git 协议优化
14
  RUN update-ca-certificates && \
15
  git config --global http.sslVerify false && \
16
  git config --global url."https://github.com/".insteadOf ssh://git@github.com/
17
 
18
  # 4. OpenClaw 核心安装与飞书插件预装
19
  RUN npm install -g openclaw@latest --unsafe-perm
20
- # 预安装飞书全套技能插件
21
  RUN openclaw plugins install @m1heng-clawd/feishu
22
 
23
  # 5. 环境变量预设
@@ -25,7 +24,7 @@ ENV PORT=7860 \
25
  OPENCLAW_GATEWAY_MODE=local \
26
  HOME=/root
27
 
28
- # 6. Python 同步引擎 (sync.py) - 负责从 HF Dataset 恢复和备份会话与配置
29
  RUN echo 'import os, sys, tarfile\n\
30
  from huggingface_hub import HfApi, hf_hub_download\n\
31
  from datetime import datetime, timedelta\n\
@@ -48,7 +47,8 @@ def restore():\n\
48
  def backup():\n\
49
  try:\n\
50
  if not repo_id or "/" not in repo_id: return\n\
51
- name = f"backup_{datetime.now().strftime(\"%Y-%m-%d\")}.tar.gz"\n\
 
52
  with tarfile.open(name, "w:gz") as tar:\n\
53
  if os.path.exists("/root/.openclaw/sessions"): tar.add("/root/.openclaw/sessions", arcname="sessions")\n\
54
  if os.path.exists("/root/.openclaw/openclaw.json"): tar.add("/root/.openclaw/openclaw.json", arcname="openclaw.json")\n\
@@ -59,18 +59,17 @@ if __name__ == "__main__":\n\
59
  if len(sys.argv) > 1 and sys.argv[1] == "backup": backup()\n\
60
  else: restore()' > /usr/local/bin/sync.py
61
 
62
- # 7. 启动控制逻辑 - 动态生成 openclaw.json 并配置飞书技能
63
  RUN echo "#!/bin/bash\n\
64
  set -e\n\
65
  mkdir -p /root/.openclaw/sessions\n\
66
  \n\
67
- # 启动前先从 Dataset 恢复上一次的配置和会话\n\
68
  python3 /usr/local/bin/sync.py restore\n\
69
  \n\
70
- # 规格化 API Base 地址\n\
71
  CLEAN_BASE=\$(echo \"\$OPENAI_API_BASE\" | sed \"s|/chat/completions||g\" | sed \"s|/v1/|/v1|g\" | sed \"s|/v1\$|/v1|g\")\n\
72
  \n\
73
- # 生成 openclaw.json (将飞书技能 ID 注册到 agents)\n\
74
  cat > /root/.openclaw/openclaw.json <<EOF\n\
75
  {\n\
76
  \"models\": {\n\
@@ -115,14 +114,11 @@ cat > /root/.openclaw/openclaw.json <<EOF\n\
115
  }\n\
116
  EOF\n\
117
  \n\
118
- # 权限加固,防止 doctor 报错\n\
119
  chmod 700 /root/.openclaw\n\
120
  chmod 600 /root/.openclaw/openclaw.json\n\
121
  \n\
122
- # 启动 6 小时一次的定时备份循环\n\
123
  (while true; do sleep 21600; python3 /usr/local/bin/sync.py backup; done) &\n\
124
  \n\
125
- # 执行配置预检并启动网关\n\
126
  openclaw doctor --fix || true\n\
127
  exec openclaw gateway run --port \$PORT --allow-unconfigured\n\
128
  " > /usr/local/bin/start-openclaw && chmod +x /usr/local/bin/start-openclaw
 
1
  # 核心镜像选择
2
  FROM node:22-slim
3
 
4
+ # 1. 基础系统依赖补全
5
  RUN apt-get update && apt-get install -y --no-install-recommends \
6
  git openssh-client build-essential python3 python3-pip \
7
  g++ make ca-certificates \
8
  && rm -rf /var/lib/apt/lists/*
9
 
10
+ # 2. 安装 Hugging Face 交互工具
11
  RUN pip3 install --no-cache-dir huggingface_hub --break-system-packages
12
 
13
+ # 3. 优化构建环境与 Git 协议
14
  RUN update-ca-certificates && \
15
  git config --global http.sslVerify false && \
16
  git config --global url."https://github.com/".insteadOf ssh://git@github.com/
17
 
18
  # 4. OpenClaw 核心安装与飞书插件预装
19
  RUN npm install -g openclaw@latest --unsafe-perm
 
20
  RUN openclaw plugins install @m1heng-clawd/feishu
21
 
22
  # 5. 环境变量预设
 
24
  OPENCLAW_GATEWAY_MODE=local \
25
  HOME=/root
26
 
27
+ # 6. Python 同步引擎 (已修复 f-string 语法错误)
28
  RUN echo 'import os, sys, tarfile\n\
29
  from huggingface_hub import HfApi, hf_hub_download\n\
30
  from datetime import datetime, timedelta\n\
 
47
  def backup():\n\
48
  try:\n\
49
  if not repo_id or "/" not in repo_id: return\n\
50
+ day = datetime.now().strftime("%Y-%m-%d")\n\
51
+ name = f"backup_{day}.tar.gz"\n\
52
  with tarfile.open(name, "w:gz") as tar:\n\
53
  if os.path.exists("/root/.openclaw/sessions"): tar.add("/root/.openclaw/sessions", arcname="sessions")\n\
54
  if os.path.exists("/root/.openclaw/openclaw.json"): tar.add("/root/.openclaw/openclaw.json", arcname="openclaw.json")\n\
 
59
  if len(sys.argv) > 1 and sys.argv[1] == "backup": backup()\n\
60
  else: restore()' > /usr/local/bin/sync.py
61
 
62
+ # 7. 启动控制逻辑
63
  RUN echo "#!/bin/bash\n\
64
  set -e\n\
65
  mkdir -p /root/.openclaw/sessions\n\
66
  \n\
67
+ # 启动前恢复备份\n\
68
  python3 /usr/local/bin/sync.py restore\n\
69
  \n\
 
70
  CLEAN_BASE=\$(echo \"\$OPENAI_API_BASE\" | sed \"s|/chat/completions||g\" | sed \"s|/v1/|/v1|g\" | sed \"s|/v1\$|/v1|g\")\n\
71
  \n\
72
+ # 生成 openclaw.json\n\
73
  cat > /root/.openclaw/openclaw.json <<EOF\n\
74
  {\n\
75
  \"models\": {\n\
 
114
  }\n\
115
  EOF\n\
116
  \n\
 
117
  chmod 700 /root/.openclaw\n\
118
  chmod 600 /root/.openclaw/openclaw.json\n\
119
  \n\
 
120
  (while true; do sleep 21600; python3 /usr/local/bin/sync.py backup; done) &\n\
121
  \n\
 
122
  openclaw doctor --fix || true\n\
123
  exec openclaw gateway run --port \$PORT --allow-unconfigured\n\
124
  " > /usr/local/bin/start-openclaw && chmod +x /usr/local/bin/start-openclaw