Spaces:
Paused
Paused
Create Dockerfile
Browse files- Dockerfile +65 -0
Dockerfile
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 阶段 1:克隆项目并构建前端
|
| 2 |
+
FROM node:lts-slim AS frontend-builder
|
| 3 |
+
|
| 4 |
+
# 安装 git
|
| 5 |
+
RUN apt-get update && \
|
| 6 |
+
apt-get install -y --no-install-recommends git && \
|
| 7 |
+
apt-get clean && \
|
| 8 |
+
rm -rf /var/lib/apt/lists/*
|
| 9 |
+
|
| 10 |
+
# 设置工作目录并克隆项目
|
| 11 |
+
WORKDIR /app
|
| 12 |
+
ARG REPO_URL=https://github.com/1653756334/PikPakInvitation.git
|
| 13 |
+
ARG BRANCH=main
|
| 14 |
+
RUN git clone --depth=1 -b ${BRANCH} ${REPO_URL} .
|
| 15 |
+
|
| 16 |
+
# 安装 pnpm 并构建前端
|
| 17 |
+
WORKDIR /app/frontend
|
| 18 |
+
RUN npm install -g pnpm
|
| 19 |
+
RUN pnpm install --frozen-lockfile
|
| 20 |
+
RUN pnpm build
|
| 21 |
+
|
| 22 |
+
# 阶段 2:构建最终镜像
|
| 23 |
+
FROM python:3.10-slim AS final
|
| 24 |
+
|
| 25 |
+
# 设置环境变量
|
| 26 |
+
ENV PYTHONUNBUFFERED=1 \
|
| 27 |
+
PYTHONDONTWRITEBYTECODE=1 \
|
| 28 |
+
PORT=5000 \
|
| 29 |
+
VIRTUAL_ENV=/opt/venv \
|
| 30 |
+
PATH="/opt/venv/bin:$PATH"
|
| 31 |
+
|
| 32 |
+
# 安装系统依赖并清理
|
| 33 |
+
RUN apt-get update && \
|
| 34 |
+
apt-get install -y --no-install-recommends gcc libc-dev && \
|
| 35 |
+
apt-get clean && \
|
| 36 |
+
rm -rf /var/lib/apt/lists/*
|
| 37 |
+
|
| 38 |
+
# 创建虚拟环境并升级 pip
|
| 39 |
+
RUN python3 -m venv $VIRTUAL_ENV && \
|
| 40 |
+
pip install --no-cache-dir --upgrade pip
|
| 41 |
+
|
| 42 |
+
# 复制并安装 Python 依赖
|
| 43 |
+
WORKDIR /app
|
| 44 |
+
COPY requirements.txt .
|
| 45 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 46 |
+
|
| 47 |
+
# 安装 huggingface_hub
|
| 48 |
+
RUN pip install --no-cache-dir huggingface_hub
|
| 49 |
+
|
| 50 |
+
# 创建应用目录
|
| 51 |
+
RUN mkdir account templates static
|
| 52 |
+
|
| 53 |
+
# 复制后端源文件
|
| 54 |
+
COPY run.py .
|
| 55 |
+
COPY utils/ ./utils/
|
| 56 |
+
|
| 57 |
+
# 从前端构建阶段复制构建产物
|
| 58 |
+
COPY --from=frontend-builder /app/frontend/dist/index.html ./templates/
|
| 59 |
+
COPY --from=frontend-builder /app/frontend/dist/* ./static/
|
| 60 |
+
|
| 61 |
+
# 暴露端口 5000
|
| 62 |
+
EXPOSE 5000
|
| 63 |
+
|
| 64 |
+
# 启动命令
|
| 65 |
+
CMD ["gunicorn", "--bind", "0.0.0.0:5000", "--workers", "1", "--threads", "4", "run:app"]
|