# 多阶段构建 Dockerfile
# 阶段1: 构建前端
FROM node:18-alpine AS frontend-builder

WORKDIR /app/frontend

# 复制前端文件
COPY mengyaprofile-frontend/package*.json ./
RUN npm install

COPY mengyaprofile-frontend/ ./
RUN npm run build

# 阶段2: 构建后端并整合
FROM python:3.11-slim

WORKDIR /app

# 安装 Python 依赖
COPY mengyaprofile-backend/requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

# 复制后端代码
COPY mengyaprofile-backend/ ./backend/

# 从前端构建阶段复制构建产物
COPY --from=frontend-builder /app/frontend/build ./frontend/build

# 创建数据目录(用于持久化)
RUN mkdir -p /app/data

# 暴露端口
EXPOSE 5000

# 设置环境变量
ENV PYTHONUNBUFFERED=1
ENV DATA_DIR=/app/data
ENV RUN_MODE=production

# 启动命令
WORKDIR /app/backend
CMD ["python", "app.py"]
