FROM python:3.9-slim ARG NB_USER=hfuser ARG NB_UID=1000 ENV APP_DIR=/app ENV HOME=${APP_DIR} ENV PATH=${APP_DIR}/.local/bin:${PATH} WORKDIR ${APP_DIR} # 系统依赖安装 (以 root) RUN apt-get update && apt-get install -y \ wget gnupg ca-certificates fonts-liberation libasound2 \ libatk-bridge2.0-0 libatk1.0-0 libatspi2.0-0 libcups2 libdbus-1-3 \ libdrm2 libgbm1 libgtk-3-0 libnspr4 libnss3 libx11-xcb1 \ libxcomposite1 libxdamage1 libxfixes3 libxkbcommon0 libxrandr2 \ xdg-utils \ && rm -rf /var/lib/apt/lists/* # 安装 Playwright Python 包 和 浏览器依赖 (以 root) RUN python3 -m pip install --no-cache-dir playwright && \ playwright install-deps firefox # 创建用户和组 RUN groupadd -r ${NB_USER} -g ${NB_UID} && \ useradd -r -u ${NB_UID} -g ${NB_USER} -d ${HOME} -s /bin/bash ${NB_USER} # 复制应用代码 COPY . ${APP_DIR}/ # 确保入口脚本可执行 RUN chmod +x ${APP_DIR}/hf-entrypoint.sh # 创建运行时目录并设置所有权给 UID 1000 RUN mkdir -p ${APP_DIR}/auth_profiles/active ${APP_DIR}/auth_profiles/saved ${APP_DIR}/logs ${APP_DIR}/.cache ${APP_DIR}/.local && \ chown -R ${NB_UID}:${NB_UID} ${APP_DIR} # 切换到非 root 用户 USER ${NB_USER} # Python 应用依赖安装 (以 UID 1000 用户) RUN python3 -m pip install --no-cache-dir -U camoufox[geoip] -r requirements.txt # 下载 Camoufox 浏览器 (以 UID 1000 用户) RUN camoufox fetch EXPOSE 7860 ENTRYPOINT ["/app/hf-entrypoint.sh"]