py-server-demo / Dockerfile
DW111D's picture
更新
4d159cb
Raw History Blame Contribute Delete
782 Bytes
# 阶段1: 构建前端
FROM node:20-alpine AS frontend-builder
WORKDIR /app
# 复制前端依赖文件
COPY ui/package.json ui/yarn.lock ./
# 安装依赖
RUN yarn install --frozen-lockfile
# 复制前端源码
COPY ui/ ./
# 构建前端
RUN yarn build
# 阶段2: 生产环境
FROM python:3.12-slim
WORKDIR /app
# 安装 Python 依赖
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
# 复制后端代码
COPY main.py ./
COPY schemas/ ./schemas/
COPY routers/ ./routers/
# 从前端构建阶段复制静态文件
COPY --from=frontend-builder /app/dist ./static/
# Hugging Face Spaces 使用 7860 端口
EXPOSE 7860
# 启动服务
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]