paleDriver7 commited on
Commit
e2668b4
·
verified ·
1 Parent(s): a1e210a

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +21 -8
Dockerfile CHANGED
@@ -1,16 +1,29 @@
1
  # Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
  # you will also find guides on how best to write your Dockerfile
3
 
4
- FROM python:3.9
5
 
6
- RUN useradd -m -u 1000 user
7
- USER user
8
- ENV PATH="/home/user/.local/bin:$PATH"
 
 
 
 
 
9
 
 
 
10
  WORKDIR /app
11
 
12
- COPY --chown=user ./requirements.txt requirements.txt
13
- RUN pip install --no-cache-dir --upgrade -r requirements.txt
 
 
 
 
 
 
 
14
 
15
- COPY --chown=user . /app
16
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
  # Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
  # you will also find guides on how best to write your Dockerfile
3
 
 
4
 
5
+ # 使用多阶段构建
6
+ # 阶段 1:构建前端
7
+ FROM node:16 AS frontend-build
8
+ WORKDIR /app/frontend
9
+ COPY frontend/package*.json ./
10
+ RUN npm install
11
+ COPY frontend/ .
12
+ RUN npm run build
13
 
14
+ # 阶段 2:运行后端 + 提供前端静态资源
15
+ FROM python:3.9
16
  WORKDIR /app
17
 
18
+ # 后端依赖
19
+ COPY backend/requirements.txt ./backend/requirements.txt
20
+ RUN pip install -r backend/requirements.txt
21
+
22
+ # 拷贝后端代码
23
+ COPY backend/ ./backend/
24
+
25
+ # 拷贝前端打包好的静态资源
26
+ COPY --from=frontend-build /app/frontend/dist ./frontend_dist
27
 
28
+ # 启动命令:运行后端,同时提供静态文件
29
+ CMD ["uvicorn", "backend.app:app", "--host", "0.0.0.0", "--port", "8000"]