wenyin commited on
Commit
63d34b2
·
verified ·
1 Parent(s): 2573c4e

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +42 -98
  2. backup.sh +38 -0
  3. entrypoint.sh +47 -0
Dockerfile CHANGED
@@ -1,98 +1,42 @@
1
- FROM node:22-slim
2
-
3
- # ─── 1. 系统基础依赖 ─────────────────────────────────────────────────────────
4
- RUN apt-get update && apt-get install -y --no-install-recommends \
5
- git \
6
- build-essential \
7
- python3 \
8
- make \
9
- g++ \
10
- curl \
11
- wget \
12
- ca-certificates \
13
- openssh-client \
14
- procps \
15
- dumb-init \
16
- jq \
17
- unzip \
18
- zip \
19
- locales \
20
- xvfb \
21
- chromium \
22
- libnss3 \
23
- libnspr4 \
24
- libatk1.0-0 \
25
- libatk-bridge2.0-0 \
26
- libcups2 \
27
- libdrm2 \
28
- libxkbcommon0 \
29
- libxcomposite1 \
30
- libxdamage1 \
31
- libxfixes3 \
32
- libxrandr2 \
33
- libgbm1 \
34
- libasound2 \
35
- libpango-1.0-0 \
36
- libcairo2 \
37
- libx11-xcb1 \
38
- libxcb-dri3-0 \
39
- libatspi2.0-0 \
40
- libwayland-client0 \
41
- fonts-liberation \
42
- fonts-noto-cjk \
43
- && locale-gen zh_CN.UTF-8 \
44
- && rm -rf /var/lib/apt/lists/*
45
-
46
- # ─── 2. 环境变量 ─────────────────────────────────────────────────────────────
47
- ENV LANG=zh_CN.UTF-8 \
48
- LANGUAGE=zh_CN:zh \
49
- LC_ALL=zh_CN.UTF-8 \
50
- # ⚠️ 注意:这里先不设置 NODE_ENV=production
51
- # 否则 npm install 会跳过 devDependencies(vite 在其中)
52
- HOME=/root \
53
- NPM_CONFIG_REGISTRY=https://registry.npmmirror.com \
54
- PLAYWRIGHT_BROWSERS_PATH=/root/.cache/ms-playwright \
55
- PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 \
56
- CHROME_BIN=/usr/bin/chromium \
57
- CHROMIUM_FLAGS="--no-sandbox --disable-dev-shm-usage --disable-gpu"
58
-
59
- # ─── 3. Git 强制使用 HTTPS ────────────────────────────────────────────────────
60
- RUN git config --global url."https://github.com/".insteadOf ssh://git@github.com/ \
61
- && git config --global url."https://github.com/".insteadOf git@github.com:
62
-
63
- # ─── 4. 全局安装 OpenClaw 中文版 ─────────────────────────────────────────────
64
- RUN npm install -g @qingchencloud/openclaw-zh \
65
- --registry https://registry.npmmirror.com \
66
- && npm cache clean --force
67
-
68
- # ─── 5. 克隆 ClawPanel ───────────────────────────────────────────────────────
69
- WORKDIR /app
70
- RUN git clone https://github.com/qingchencloud/clawpanel.git .
71
-
72
- # ─── 6. 安装【全部】依赖(含 devDependencies)────────────────────────────────
73
- # 关键:显式指定 --include=dev,确保 vite 等构建工具被安装
74
- RUN npm install --include=dev \
75
- --registry https://registry.npmmirror.com \
76
- && npm cache clean --force
77
-
78
- # ─── 7. 构建前端 ──────────────────────────────────────────────────────────────
79
- RUN npm run build
80
-
81
- # ─── 8. 清理 devDependencies(减小镜像体积)─────────────────────────────────
82
- # 构建完成后删除开发依赖,只保留运行时所需
83
- RUN npm prune --omit=dev \
84
- && npm cache clean --force
85
-
86
- # ─── 9. 现在才设置 production 环境变量 ───────────────────────────────────────
87
- ENV NODE_ENV=production
88
-
89
- # ─── 10. 目录准备 ─────────────────────────────────────────────────────────────
90
- RUN mkdir -p /root/.openclaw \
91
- && mkdir -p /root/.cache/ms-playwright
92
-
93
- # ─── 11. 暴露端口 ─────────────────────────────────────────────────────────────
94
- EXPOSE 7860
95
-
96
- # ─── 12. 启动 ────────────────────────────────────────────────────────────────
97
- ENTRYPOINT ["dumb-init", "--"]
98
- CMD ["npm", "run", "serve", "--", "--port", "7860", "--host", "0.0.0.0"]
 
1
+ FROM node:22-slim
2
+
3
+ # ─── 1. 系统基础依赖 ─────────────────────────────────────────────────────────
4
+ RUN apt-get update && apt-get install -y --no-install-recommends \
5
+ git build-essential python3 python3-pip make g++ curl wget ca-certificates \
6
+ openssh-client procps dumb-init jq unzip zip locales xvfb \
7
+ chromium cron libnss3 libnspr4 libatk1.0-0 libatk-bridge2.0-0 libcups2 \
8
+ libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 libxfixes3 \
9
+ libxrandr2 libgbm1 libasound2 libpango-1.0-0 libcairo2 \
10
+ libx11-xcb1 libxcb-dri3-0 libatspi2.0-0 libwayland-client0 \
11
+ fonts-liberation fonts-noto-cjk \
12
+ && locale-gen zh_CN.UTF-8 \
13
+ && rm -rf /var/lib/apt/lists/*
14
+
15
+ # 安装 Hugging Face SDK (兼容 Debian 12 的外部包管理)
16
+ RUN pip3 install --no-cache-dir huggingface_hub --break-system-packages
17
+
18
+ # ─── 2. 环境变量 ─────────────────────────────────────────────────────────────
19
+ ENV LANG=zh_CN.UTF-8 \
20
+ LANGUAGE=zh_CN:zh \
21
+ LC_ALL=zh_CN.UTF-8 \
22
+ HOME=/root \
23
+ NPM_CONFIG_REGISTRY=https://registry.npmmirror.com \
24
+ PLAYWRIGHT_BROWSERS_PATH=/root/.cache/ms-playwright \
25
+ PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 \
26
+ CHROME_BIN=/usr/bin/chromium \
27
+ NODE_ENV=production
28
+
29
+ WORKDIR /app
30
+
31
+ # 复制脚本
32
+ COPY entrypoint.sh /usr/local/bin/entrypoint.sh
33
+ COPY backup.sh /usr/local/bin/backup.sh
34
+ RUN chmod +x /usr/local/bin/entrypoint.sh /usr/local/bin/backup.sh
35
+
36
+ # ─── 3. 配置 Cron 定时任务 (每小时执行备份) ──────────────────────────────────
37
+ RUN echo "0 * * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1" | crontab -
38
+
39
+ EXPOSE 7860
40
+
41
+ ENTRYPOINT ["dumb-init", "--"]
42
+ CMD ["/usr/local/bin/entrypoint.sh"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
backup.sh ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ REPO_ID="wenyin/openclaw"
4
+ FILE_NAME="clawpanel.zip"
5
+ APP_DIR="/app"
6
+ TEMP_ZIP="/tmp/clawpanel_backup.zip"
7
+
8
+ echo "[$(date)] 执行周期性备份..."
9
+
10
+ if [ -z "$HF_TOKEN" ]; then
11
+ echo "❌ 缺少 HF_TOKEN,跳过备份。"
12
+ exit 1
13
+ fi
14
+
15
+ # 1. 压缩当前应用目录(排除 node_modules 减小体积)
16
+ cd "$APP_DIR"
17
+ # 注意:启动时会自动 npm install,所以备份代码和构建后的产物即可
18
+ zip -r -q "$TEMP_ZIP" . -x "node_modules/*"
19
+
20
+ # 2. 调用 API 上传覆盖
21
+ python3 -c "
22
+ from huggingface_hub import HfApi
23
+ import os
24
+ api = HfApi(token=os.getenv('HF_TOKEN'))
25
+ try:
26
+ api.upload_file(
27
+ path_or_fileobj='$TEMP_ZIP',
28
+ path_in_repo='$FILE_NAME',
29
+ repo_id='$REPO_ID',
30
+ repo_type='dataset'
31
+ )
32
+ print('✅ 备份上传成功')
33
+ except Exception as e:
34
+ print(f'❌ 备份上传失败: {e}')
35
+ "
36
+
37
+ # 3. 清理临时压缩包
38
+ rm -f "$TEMP_ZIP"
entrypoint.sh ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ REPO_ID="wenyin/openclaw"
5
+ FILE_NAME="clawpanel.zip"
6
+ APP_DIR="/app"
7
+
8
+ echo "🔄 正在检查并更新 ClawPanel..."
9
+
10
+ # 1. 尝试从 Hugging Face 获取最新备份
11
+ echo "🔍 正在从 Hugging Face 获取远程备份..."
12
+ python3 -c "
13
+ from huggingface_hub import hf_hub_download
14
+ import os
15
+ try:
16
+ path = hf_hub_download(repo_id='$REPO_ID', filename='$FILE_NAME', repo_type='dataset', token=os.getenv('HF_TOKEN'))
17
+ print(f'HF_PATH:{path}')
18
+ except Exception as e:
19
+ print('HF_NOT_FOUND')
20
+ " > /tmp/hf_result.txt
21
+
22
+ HF_PATH=$(grep "HF_PATH:" /tmp/hf_result.txt | cut -d':' -f2)
23
+
24
+ if [ -n "$HF_PATH" ]; then
25
+ echo "📦 找到备份文件,正在覆盖安装..."
26
+ rm -rf "$APP_DIR"/*
27
+ unzip -o "$HF_PATH" -d "$APP_DIR"
28
+ cd "$APP_DIR"
29
+ # 这里是“覆盖安装并更新”的关键步骤
30
+ echo "⚙️ 正在通过 npm install 更新依赖..."
31
+ npm install --omit=dev --registry https://registry.npmmirror.com
32
+ else
33
+ echo "🚀 未发现备份,开始全新安装..."
34
+ git clone https://github.com/qingchencloud/clawpanel.git .
35
+ npm install --include=dev --registry https://registry.npmmirror.com
36
+ npm run build
37
+ npm prune --omit=dev
38
+ # 全新安装后立即备份一次
39
+ /usr/local/bin/backup.sh
40
+ fi
41
+
42
+ # 2. 启动 Cron 定时备份任务
43
+ service cron start
44
+
45
+ # 3. 运行程序
46
+ echo "✨ ClawPanel 启动成功!"
47
+ exec npm run serve -- --port 7860 --host 0.0.0.0