Update Dockerfile
Browse files- 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 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
|
|
|
|
|
|
| 10 |
WORKDIR /app
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "
|
|
|
|
| 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"]
|