Spaces:
Sleeping
Sleeping
# Force rebuild | |
# 阶段 1:克隆项目并构建前端 | |
FROM node:lts-slim AS frontend-builder | |
# 安装 git 和 ca-certificates | |
RUN apt-get update && \ | |
apt-get install -y --no-install-recommends git ca-certificates && \ | |
apt-get clean && \ | |
rm -rf /var/lib/apt/lists/* | |
# 设置工作目录并克隆项目 | |
WORKDIR /app | |
#ARG REPO_URL=https://github.com/1653756334/PikPakInvitation.git | |
ARG REPO_URL=https://github.com/hhsw2015/PikPakInvitation.git | |
ARG BRANCH=main | |
RUN git clone -b ${BRANCH} ${REPO_URL} . | |
# 安装 pnpm 并构建前端 | |
WORKDIR /app/frontend | |
RUN npm install -g pnpm | |
RUN pnpm install --frozen-lockfile | |
RUN pnpm build | |
# 阶段 2:构建最终镜像 | |
FROM python:3.10-slim AS final | |
# 设置环境变量 | |
ENV PYTHONUNBUFFERED=1 \ | |
PYTHONDONTWRITEBYTECODE=1 \ | |
PORT=5000 \ | |
VIRTUAL_ENV=/opt/venv \ | |
PATH="/opt/venv/bin:$PATH" | |
# 安装系统依赖并清理 | |
RUN apt-get update && \ | |
apt-get install -y --no-install-recommends gcc libc-dev && \ | |
apt-get clean && \ | |
rm -rf /var/lib/apt/lists/* | |
# 创建虚拟环境并升级 pip | |
RUN python3 -m venv $VIRTUAL_ENV && \ | |
pip install --no-cache-dir --upgrade pip | |
# 设置工作目录 | |
WORKDIR /app | |
# 从 frontend-builder 阶段复制 requirements.txt | |
COPY --from=frontend-builder /app/requirements.txt . | |
# 安装 Python 依赖 | |
RUN pip install --no-cache-dir -r requirements.txt | |
# 安装 huggingface_hub | |
RUN pip install --no-cache-dir huggingface_hub | |
# 创建应用目录 | |
RUN mkdir account templates static | |
# 从 frontend-builder 阶段复制后端源文件 | |
COPY --from=frontend-builder /app/run.py . | |
COPY --from=frontend-builder /app/utils/ ./utils/ | |
# 从前端构建阶段复制构建产物 | |
COPY --from=frontend-builder /app/frontend/dist/index.html ./templates/ | |
COPY --from=frontend-builder /app/frontend/dist/* ./static/ | |
COPY sync_data.sh / | |
COPY entrypoint.sh /entrypoint.sh | |
RUN chmod +x /sync_data.sh /entrypoint.sh | |
# 创建非 root 用户 | |
RUN useradd -m -u 1000 appuser && \ | |
chown -R appuser:appuser /app | |
# 切换到非 root 用户 | |
USER appuser | |
# 暴露端口 5000 | |
EXPOSE 5000 | |
# 使用 entrypoint.sh 作为启动命令 | |
CMD ["/entrypoint.sh"] | |