Spaces:
Sleeping
Sleeping
File size: 2,160 Bytes
a4d50c7 bb32229 83ef536 bb32229 83ef536 bb32229 c040788 bb32229 1888133 bb32229 744229a bb32229 83ef536 bb32229 18152e3 bb32229 18152e3 bb32229 a4d50c7 bb32229 18152e3 bb32229 5577980 216b2fd 18152e3 216b2fd 18152e3 bb32229 5577980 0e8e893 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# 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"]
|