# =============================================================================
# 禾瑞思航·低代码 AI 模型训练系统 — 多阶段构建
# Stage 1: 构建 Vue 前端静态资源
# Stage 2: 安装 Python 依赖并运行 FastAPI
# =============================================================================

# --- 前端构建 ---
FROM node:22-alpine AS frontend-build

WORKDIR /app

COPY package.json package-lock.json* ./
RUN npm ci 2>/dev/null || npm install

COPY index.html vite.config.ts tsconfig.json tsconfig.node.json ./
COPY public ./public
COPY src ./src

RUN npm run build

# --- 后端运行 ---
FROM python:3.11-slim

WORKDIR /app

ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    TZ=Asia/Shanghai

# OpenCV、curl（健康检查）等系统依赖
RUN apt-get update && apt-get install -y --no-install-recommends \
    libgl1 \
    libglib2.0-0 \
    libsm6 \
    libxext6 \
    libxrender1 \
    curl \
    && rm -rf /var/lib/apt/lists/*

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY src/backend ./src/backend
COPY --from=frontend-build /app/dist ./dist

RUN mkdir -p uploads data models logs

EXPOSE 8000

CMD ["python", "-m", "uvicorn", "src.backend.main:app", "--host", "0.0.0.0", "--port", "8000"]
