File size: 1,228 Bytes
2d4ab0a
 
 
 
 
 
 
 
 
 
 
 
 
73cb997
2d4ab0a
 
 
 
 
 
 
 
73cb997
 
 
2d4ab0a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73cb997
2d4ab0a
 
 
 
 
 
 
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
# ==========================================
# Stage 1: Build Frontend (Next.js)
# ==========================================
FROM node:20-alpine AS frontend-builder
WORKDIR /app-frontend

# 安装依赖
COPY ./frontend/package*.json ./
RUN npm install

# 构建静态资源
COPY ./frontend .
ENV NEXT_TELEMETRY_DISABLED=1
# 确保 next 可以在 alpine 中运行
RUN npm run build

# ==========================================
# Stage 2: Build Backend & Runtime
# ==========================================
FROM python:3.11-slim
WORKDIR /app

# 创建数据目录
RUN mkdir -p /app/data && chmod 777 /app/data

# 安装系统依赖 (Git用于HF SDK)
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*

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

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

# 从 Stage 1 复制前端静态文件到 FastAPI 的 static 目录
COPY --from=frontend-builder /app-frontend/out /app/static

# 环境变量设置
ENV HF_HOME=/tmp/.huggingface
ENV DUCKDB_PATH=/app/data/stock_data.duckdb
ENV PORT=7860

# 暴露端口
EXPOSE 7860

# 启动命令
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]