1guow commited on
Commit
a068bdd
·
verified ·
1 Parent(s): f07cd8f

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +43 -45
Dockerfile CHANGED
@@ -1,9 +1,8 @@
1
  FROM ubuntu:24.04
2
 
3
- # 设置环境变量,避免安装过程中的交互
4
  ENV DEBIAN_FRONTEND=noninteractive
5
 
6
- # 更新系统并安装必要工具 (Node.js 22, Python 3, Git, OpenSSH 等)
7
  RUN apt-get update && apt-get install -y \
8
  curl wget gnupg ca-certificates lsb-release \
9
  python3 python3-pip git openssh-client vim net-tools dnsutils cron \
@@ -20,46 +19,44 @@ RUN pip3 install --break-system-packages huggingface_hub
20
  RUN npm install -g openclaw@latest
21
 
22
  # --- 创建备份与恢复脚本 (sync.py) ---
23
- RUN echo #!/usr/bin/env python3
24
- import os
25
- import sys
26
- from huggingface_hub import snapshot_download, upload_folder
27
-
28
- BACKUP_PATH = "/root/.openclaw"
29
- DATASET_REPO = os.getenv("HF_DATASET")
30
- TOKEN = os.getenv("HF_TOKEN")
31
-
32
- if not DATASET_REPO or not TOKEN:
33
- print("Error: HF_DATASET or HF_TOKEN not set.")
34
- sys.exit(1)
35
-
36
- if len(sys.argv) > 1 and sys.argv[1] == "restore":
37
- print(f"Restoring backup from {DATASET_REPO} to {BACKUP_PATH}...")
38
- try:
39
- snapshot_download(
40
- repo_id=DATASET_REPO,
41
- repo_type="dataset",
42
- local_dir=BACKUP_PATH,
43
- token=TOKEN
44
- )
45
- print("Restore successful!")
46
- except Exception as e:
47
- print(f"Restore failed: {e}")
48
- else:
49
- print(f"Backing up {BACKUP_PATH} to {DATASET_REPO}...")
50
- try:
51
- upload_folder(
52
- folder_path=BACKUP_PATH,
53
- repo_id=DATASET_REPO,
54
- repo_type="dataset",
55
- token=TOKEN
56
- )
57
- print("Backup successful!")
58
- except Exception as e:
59
- print(f"Backup failed: {e}")
60
  \n\
61
- if __name__ == "__main__":\n\
62
- main()' > /root/sync.py
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
 
64
  # --- 创建启动脚本 (start-openclaw.sh) ---
65
  RUN echo '#!/bin/bash\n\
@@ -67,9 +64,10 @@ RUN echo '#!/bin/bash\n\
67
  echo "Restoring backup from HF Dataset..."\n\
68
  python3 /root/sync.py restore\n\
69
  \n\
70
- # 2. 初始化 OpenClaw 配置(新增这行)
71
- echo "Running openclaw setup..."
72
- openclaw setup --non-interactive --set gateway.mode=local
 
73
  # 3. 启动 OpenClaw\n\
74
  echo "Starting OpenClaw..."\n\
75
  openclaw gateway --port 7860 &\n\
@@ -80,7 +78,7 @@ echo "*/15 * * * * root python3 /root/sync.py >> /var/log/cron.log 2>&1" > /etc/
80
  cron\n\
81
  \n\
82
  # 5. 捕获退出信号,确保停止前做最后一次备份\n\
83
- trap "echo \\"Stopping...\\"; python3 /root/sync.py; kill $CLAW_PID; exit 0" SIGTERM SIGINT\n\
84
  \n\
85
  echo "OpenClaw is running on port 7860!"\n\
86
  wait $CLAW_PID' > /root/start-openclaw.sh && chmod +x /root/start-openclaw.sh
 
1
  FROM ubuntu:24.04
2
 
 
3
  ENV DEBIAN_FRONTEND=noninteractive
4
 
5
+ # 更新系统并安装必要工具
6
  RUN apt-get update && apt-get install -y \
7
  curl wget gnupg ca-certificates lsb-release \
8
  python3 python3-pip git openssh-client vim net-tools dnsutils cron \
 
19
  RUN npm install -g openclaw@latest
20
 
21
  # --- 创建备份与恢复脚本 (sync.py) ---
22
+ RUN echo '#!/usr/bin/env python3\n\
23
+ import os\n\
24
+ import sys\n\
25
+ from huggingface_hub import snapshot_download, upload_folder\n\
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  \n\
27
+ BACKUP_PATH = "/root/.openclaw"\n\
28
+ DATASET_REPO = os.getenv("HF_DATASET")\n\
29
+ TOKEN = os.getenv("HF_TOKEN")\n\
30
+ \n\
31
+ if not DATASET_REPO or not TOKEN:\n\
32
+ print("Error: HF_DATASET or HF_TOKEN not set.")\n\
33
+ sys.exit(1)\n\
34
+ \n\
35
+ if len(sys.argv) > 1 and sys.argv[1] == "restore":\n\
36
+ print(f"Restoring backup from {DATASET_REPO} to {BACKUP_PATH}...")\n\
37
+ try:\n\
38
+ snapshot_download(\n\
39
+ repo_id=DATASET_REPO,\n\
40
+ repo_type="dataset",\n\
41
+ local_dir=BACKUP_PATH,\n\
42
+ token=TOKEN\n\
43
+ )\n\
44
+ print("Restore successful!")\n\
45
+ except Exception as e:\n\
46
+ print(f"Restore failed: {e}")\n\
47
+ else:\n\
48
+ print(f"Backing up {BACKUP_PATH} to {DATASET_REPO}...")\n\
49
+ try:\n\
50
+ upload_folder(\n\
51
+ folder_path=BACKUP_PATH,\n\
52
+ repo_id=DATASET_REPO,\n\
53
+ repo_type="dataset",\n\
54
+ token=TOKEN\n\
55
+ )\n\
56
+ print("Backup successful!")\n\
57
+ except Exception as e:\n\
58
+ print(f"Backup failed: {e}")\n\
59
+ ' > /root/sync.py
60
 
61
  # --- 创建启动脚本 (start-openclaw.sh) ---
62
  RUN echo '#!/bin/bash\n\
 
64
  echo "Restoring backup from HF Dataset..."\n\
65
  python3 /root/sync.py restore\n\
66
  \n\
67
+ # 2. 初始化 OpenClaw 配置\n\
68
+ echo "Running openclaw setup..."\n\
69
+ openclaw setup --non-interactive --set gateway.mode=local\n\
70
+ \n\
71
  # 3. 启动 OpenClaw\n\
72
  echo "Starting OpenClaw..."\n\
73
  openclaw gateway --port 7860 &\n\
 
78
  cron\n\
79
  \n\
80
  # 5. 捕获退出信号,确保停止前做最后一次备份\n\
81
+ trap "echo \"Stopping...\"; python3 /root/sync.py; kill $CLAW_PID; exit 0" SIGTERM SIGINT\n\
82
  \n\
83
  echo "OpenClaw is running on port 7860!"\n\
84
  wait $CLAW_PID' > /root/start-openclaw.sh && chmod +x /root/start-openclaw.sh