nbugs commited on
Commit
d1a7f47
·
verified ·
1 Parent(s): c89ac8b

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +43 -29
Dockerfile CHANGED
@@ -1,41 +1,55 @@
 
1
  FROM ghcr.io/open-webui/open-webui:main
2
 
3
- # Install Python dependencies
4
- RUN apt-get update && apt-get install -y python3 python3-pip --no-install-recommends && \
 
 
 
 
 
 
5
  pip3 install --no-cache-dir huggingface_hub && \
6
  apt-get clean && \
7
  rm -rf /var/lib/apt/lists/*
8
 
9
- # Copy custom files
 
 
 
 
 
 
 
 
 
 
10
  COPY custom.css /app/build/assets/
11
  COPY custom.js /app/build/assets/
12
  COPY editor.css /app/build/assets/
13
  COPY editor.js /app/build/assets/
14
 
15
- # Copy backup script
16
- COPY sync_data.sh /app/sync_data.sh
17
-
18
- # Modify HTML references
19
- RUN sed -i 's|</head>|<link rel="stylesheet" href="assets/editor.css"></link><link rel="stylesheet" href="assets/custom.css"></link></head>|' /app/build/index.html && \
20
- sed -i 's|</body>|<script src="assets/editor.js"></script><script src="assets/custom.js"></script></body>|' /app/build/index.html
21
-
22
- # Set permissions
23
- RUN chmod -R 777 ./data 2>/dev/null || true && \
24
- chmod -R 777 /app/backend/open_webui/static 2>/dev/null || true && \
25
- chmod +x /app/sync_data.sh
26
-
27
- # Important: Don't override the ENTRYPOINT
28
- # Instead, modify the original entrypoint to run our script first
29
- COPY --from=busybox:1.36 /bin/sh /bin/sh
30
- RUN ORIGINAL_ENTRYPOINT=$(cat /proc/1/cmdline | tr '\0' ' ' | awk '{print $1}') && \
31
- if [ -f "$ORIGINAL_ENTRYPOINT" ]; then \
32
- mv "$ORIGINAL_ENTRYPOINT" "$ORIGINAL_ENTRYPOINT.original" && \
33
- echo '#!/bin/sh' > "$ORIGINAL_ENTRYPOINT" && \
34
- echo '# Run backup script in background' >> "$ORIGINAL_ENTRYPOINT" && \
35
- echo 'if [ -f "/app/sync_data.sh" ]; then' >> "$ORIGINAL_ENTRYPOINT" && \
36
- echo ' (nohup bash /app/sync_data.sh > /tmp/sync.log 2>&1 &)' >> "$ORIGINAL_ENTRYPOINT" && \
37
- echo 'fi' >> "$ORIGINAL_ENTRYPOINT" && \
38
- echo '# Run original entrypoint' >> "$ORIGINAL_ENTRYPOINT" && \
39
- echo "exec $ORIGINAL_ENTRYPOINT.original \"\$@\"" >> "$ORIGINAL_ENTRYPOINT" && \
40
- chmod +x "$ORIGINAL_ENTRYPOINT"; \
41
  fi
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 使用基础镜像
2
  FROM ghcr.io/open-webui/open-webui:main
3
 
4
+ # 设置工作目录
5
+ WORKDIR /app
6
+
7
+ # 安装依赖(python3, pip, curl),安装 Python 包,并清理apt缓存
8
+ # DEBIAN_FRONTEND=noninteractive 避免交互式提示
9
+ RUN export DEBIAN_FRONTEND=noninteractive && \
10
+ apt-get update && \
11
+ apt-get install -y --no-install-recommends python3 python3-pip curl && \
12
  pip3 install --no-cache-dir huggingface_hub && \
13
  apt-get clean && \
14
  rm -rf /var/lib/apt/lists/*
15
 
16
+ # 复制 Python 同步脚本
17
+ COPY hf_sync.py /app/hf_sync.py
18
+
19
+ # 复制主同步脚本
20
+ COPY sync_data.sh /app/sync_data.sh
21
+
22
+ # 复制自定义入口点脚本
23
+ COPY entrypoint.sh /app/entrypoint.sh
24
+
25
+ # 复制自定义资源文件
26
+ # !! 注意:请确认 /app/build/assets 是基础镜像中存放前端资源的正确路径 !!
27
  COPY custom.css /app/build/assets/
28
  COPY custom.js /app/build/assets/
29
  COPY editor.css /app/build/assets/
30
  COPY editor.js /app/build/assets/
31
 
32
+ # index.html 注入 CSS/JS 引用
33
+ # !! 注意:请确认 /app/build/index.html 是基础镜像中主HTML文件的正确路径 !!
34
+ # 如果文件不存在,RUN命令会失败,这有助于发现路径错误
35
+ RUN if [ -f /app/build/index.html ]; then \
36
+ sed -i \
37
+ -e 's|</head>|<link rel="stylesheet" href="assets/editor.css">\n</head>|' \
38
+ -e 's|</body>|<script src="assets/editor.js"></script>\n</body>|' \
39
+ -e 's|</head>|<link rel="stylesheet" href="assets/custom.css">\n</head>|' \
40
+ -e 's|</body>|<script src="assets/custom.js"></script>\n</body>|' \
41
+ /app/build/index.html; \
42
+ else \
43
+ echo "警告:未找到 /app/build/index.html,跳过注入CSS/JS。"; \
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  fi
45
+
46
+ # 设置脚本执行权限
47
+ RUN chmod +x /app/sync_data.sh && \
48
+ chmod +x /app/hf_sync.py && \
49
+ chmod +x /app/entrypoint.sh
50
+
51
+ # 设置入口点
52
+ ENTRYPOINT ["/app/entrypoint.sh"]
53
+
54
+ # 保留基础镜像的 CMD。 entrypoint.sh 脚本最后会用 exec "$@" 执行它。
55
+ # 例如,如果基础镜像是 CMD ["/app/start.sh"],entrypoint.sh 会最终执行 /app/start.sh