My_AI / Dockerfile
sunboy0628's picture
Update Dockerfile
71db86b verified
FROM python:3.10-slim-bullseye
LABEL maintainer="foo@bar.com"
# 构建参数配置
ARG TZ='Asia/Shanghai'
ARG REPO_URL="https://github.com/zhayujie/chatgpt-on-wechat.git"
ARG BRANCH="master"
# 是否安装浏览器 (Playwright/Chromium)
ARG INSTALL_BROWSER=true
# 是否使用国内镜像源加速
ARG USE_CN_MIRROR=false
ENV PLAYWRIGHT_BROWSERS_PATH=/app/ms-playwright
ENV BUILD_PREFIX=/app
# 1. 配置镜像源 (可选)
RUN if [ "$USE_CN_MIRROR" = "true" ]; then \
sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list; \
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple/; \
fi
# 2. 核心构建步骤:安装工具 -> 克隆代码 -> 删除 .git -> 安装依赖 -> 清理环境
RUN apt-get update \
&& apt-get install -y --no-install-recommends r-cran-ggplot2 git bash ffmpeg espeak libavcodec-extra \
# 克隆指定分支并进入目录
&& git clone -b ${BRANCH} ${REPO_URL} ${BUILD_PREFIX} \
&& cd ${BUILD_PREFIX} \
# 【关键步骤】删除 .git 文件夹以减小体积
&& rm -rf .git \
# 准备基础配置文件
&& cp config-template.json config.json \
# 更新 pip 并安装 Python 依赖
&& /usr/local/bin/python -m pip install --no-cache --upgrade pip \
&& pip install --no-cache -r requirements.txt \
&& pip install --no-cache -r requirements-optional.txt \
&& pip install --no-cache -e . \
# 浏览器环境安装逻辑
&& if [ "$INSTALL_BROWSER" = "true" ]; then \
apt-get install -y --no-install-recommends fonts-wqy-zenhei \
&& pip install --no-cache "playwright==1.52.0" \
&& python -m playwright install-deps chromium \
&& mkdir -p /app/ms-playwright \
&& if [ "$USE_CN_MIRROR" = "true" ]; then \
PLAYWRIGHT_DOWNLOAD_HOST=https://registry.npmmirror.com/-/binary/playwright \
python -m playwright install chromium; \
else \
python -m playwright install chromium; \
fi; \
fi \
&& rm -rf /var/lib/apt/lists/* \
# 修改用户创建逻辑
&& groupadd -g 1000 agent \
&& useradd -r -u 1000 -g agent -s /bin/bash -d /home/agent agent \
&& mkdir -p /home/agent/cow ${BUILD_PREFIX} \
&& chown -R agent:agent /home/agent ${BUILD_PREFIX} /usr/local/lib
# 这一步非常重要:HF 挂载 /home 后,原有的文件夹可能会被覆盖
# 我们需要确保程序有权在 /app 中写入(日志、临时文件等)
WORKDIR ${BUILD_PREFIX}
# 拷贝 entrypoint 并赋权
COPY --chown=agent:agent --chmod=755 entrypoint.sh /entrypoint.sh
# 显式切换到 UID 1000
USER 1000
ENTRYPOINT ["/entrypoint.sh"]