sunboy0628 commited on
Commit
3869da7
·
verified ·
1 Parent(s): f43774c

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +62 -7
Dockerfile CHANGED
@@ -1,13 +1,68 @@
1
- FROM zhayujie/chatgpt-on-wechat:master
 
2
 
3
- WORKDIR /app
 
 
 
 
 
 
 
4
 
5
- ENV PORT=7860
6
- EXPOSE 7860
7
 
8
- USER root
 
 
 
 
9
 
10
- COPY entrypoint.sh /entrypoint.sh
11
- RUN chmod +x /entrypoint.sh
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  ENTRYPOINT ["/entrypoint.sh"]
 
1
+ FROM python:3.10-slim-bullseye
2
+ LABEL maintainer="foo@bar.com"
3
 
4
+ # 构建参数配置
5
+ ARG TZ='Asia/Shanghai'
6
+ ARG REPO_URL="https://github.com/zhayujie/chatgpt-on-wechat.git"
7
+ ARG BRANCH="master"
8
+ # 是否安装浏览器 (Playwright/Chromium)
9
+ ARG INSTALL_BROWSER=true
10
+ # 是否使用国内镜像源加速
11
+ ARG USE_CN_MIRROR=false
12
 
13
+ ENV PLAYWRIGHT_BROWSERS_PATH=/app/ms-playwright
14
+ ENV BUILD_PREFIX=/app
15
 
16
+ # 1. 配置镜像源 (可选)
17
+ RUN if [ "$USE_CN_MIRROR" = "true" ]; then \
18
+ sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list; \
19
+ pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple/; \
20
+ fi
21
 
22
+ # 2. 核心构建步骤:安装工具 -> 克隆代码 -> 删除 .git -> 安装依赖 -> 清理环境
23
+ RUN apt-get update \
24
+ && apt-get install -y --no-install-recommends git bash ffmpeg espeak libavcodec-extra \
25
+ # 克隆指定分支并进入目录
26
+ && git clone -b ${BRANCH} ${REPO_URL} ${BUILD_PREFIX} \
27
+ && cd ${BUILD_PREFIX} \
28
+ # 【关键步骤】删除 .git 文件夹以减小体积
29
+ && rm -rf .git \
30
+ # 准备基础配置文件
31
+ && cp config-template.json config.json \
32
+ # 更新 pip 并安装 Python 依赖
33
+ && /usr/local/bin/python -m pip install --no-cache --upgrade pip \
34
+ && pip install --no-cache -r requirements.txt \
35
+ && pip install --no-cache -r requirements-optional.txt \
36
+ && pip install --no-cache -e . \
37
+ # 浏览器环境安装逻辑
38
+ && if [ "$INSTALL_BROWSER" = "true" ]; then \
39
+ apt-get install -y --no-install-recommends fonts-wqy-zenhei \
40
+ && pip install --no-cache "playwright==1.52.0" \
41
+ && python -m playwright install-deps chromium \
42
+ && mkdir -p /app/ms-playwright \
43
+ && if [ "$USE_CN_MIRROR" = "true" ]; then \
44
+ PLAYWRIGHT_DOWNLOAD_HOST=https://registry.npmmirror.com/-/binary/playwright \
45
+ python -m playwright install chromium; \
46
+ else \
47
+ python -m playwright install chromium; \
48
+ fi; \
49
+ fi \
50
+ # 权限与用户设置
51
+ && rm -rf /var/lib/apt/lists/* \
52
+ && mkdir -p /home/agent/cow \
53
+ && groupadd -r agent \
54
+ && useradd -r -g agent -s /bin/bash -d /home/agent agent \
55
+ && chown -R agent:agent /home/agent ${BUILD_PREFIX} /usr/local/lib
56
+
57
+ WORKDIR ${BUILD_PREFIX}
58
+
59
+ # 3. 设置启动脚本
60
+ # 从克隆下来的代码中提取 entrypoint.sh
61
+ RUN cp ${BUILD_PREFIX}/docker/entrypoint.sh /entrypoint.sh \
62
+ && chmod +x /entrypoint.sh \
63
+ && chown agent:agent /entrypoint.sh
64
+
65
+ # 切换到非 root 用户运行
66
+ USER agent
67
 
68
  ENTRYPOINT ["/entrypoint.sh"]