SarahXia0405 commited on
Commit
ca5f288
·
verified ·
1 Parent(s): 52fd618

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +32 -14
Dockerfile CHANGED
@@ -1,10 +1,30 @@
1
- FROM python:3.11-slim
 
 
 
2
 
3
- # ---- system deps (node for Vite build) ----
4
- RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
5
- RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
6
- && apt-get update && apt-get install -y nodejs \
7
- && rm -rf /var/lib/apt/lists/*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  WORKDIR /app
10
 
@@ -12,16 +32,14 @@ WORKDIR /app
12
  COPY requirements.txt /app/requirements.txt
13
  RUN pip install --no-cache-dir -r /app/requirements.txt
14
 
15
- # ---- Copy source ----
16
  COPY api/ /app/api/
17
- COPY web/ /app/web/
18
 
19
- # ---- Build React ----
20
- WORKDIR /app/web
21
- RUN npm install
22
- RUN npm run build
23
 
24
  # ---- Run API (serves web dist too) ----
25
- WORKDIR /app
26
- ENV PORT=7860
27
  CMD ["uvicorn", "api.server:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
+ # =========================
2
+ # Stage 1: Build Frontend
3
+ # =========================
4
+ FROM node:20-slim AS web_builder
5
 
6
+ WORKDIR /web
7
+
8
+ # 1) 先只拷贝依赖声明,最大化缓存命中
9
+ COPY web/package.json web/package-lock.json* ./
10
+
11
+ # 2) 推荐 npm ci:更稳定、更可复现;如果没有 lock 文件会自动失败
12
+ # 如果你没有 package-lock.json,就把 npm ci 改成 npm install
13
+ RUN if [ -f package-lock.json ]; then npm ci; else npm install; fi
14
+
15
+ # 3) 再拷贝其余前端代码并构建
16
+ COPY web/ ./
17
+ RUN npm run build
18
+
19
+
20
+ # =========================
21
+ # Stage 2: Python Runtime
22
+ # =========================
23
+ FROM python:3.11-slim AS runtime
24
+
25
+ ENV PYTHONDONTWRITEBYTECODE=1 \
26
+ PYTHONUNBUFFERED=1 \
27
+ PORT=7860
28
 
29
  WORKDIR /app
30
 
 
32
  COPY requirements.txt /app/requirements.txt
33
  RUN pip install --no-cache-dir -r /app/requirements.txt
34
 
35
+ # ---- Copy backend ----
36
  COPY api/ /app/api/
 
37
 
38
+ # ---- Copy built frontend dist from Stage 1 ----
39
+ # server.py expects WEB_DIST = ../web/dist relative to /app/api
40
+ # so we must place it at /app/web/dist
41
+ COPY --from=web_builder /web/dist /app/web/dist
42
 
43
  # ---- Run API (serves web dist too) ----
44
+ EXPOSE 7860
 
45
  CMD ["uvicorn", "api.server:app", "--host", "0.0.0.0", "--port", "7860"]