Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files1234567891011121314151617181920212223242526272829301 unmodified line3233343536373839404142434445# =========================# Stage 1: Build Frontend# =========================FROM node:20-slim AS web_builderWORKDIR /web# 1) 先只拷贝依赖声明,最大化缓存命中COPY web/package.json web/package-lock.json* ./# 2) 推荐 npm ci:更稳定、更可复现;如果没有 lock 文件会自动失败# 如果你没有 package-lock.json,就把 npm ci 改成 npm installRUN if [ -f package-lock.json ]; then npm ci; else npm install; fi# 3) 再拷贝其余前端代码并构建COPY web/ ./RUN npm run build# =========================# Stage 2: Python Runtime# =========================FROM python:3.11-slim AS runtimeENV PYTHONDONTWRITEBYTECODE=1 \PYTHONUNBUFFERED=1 \PORT=7860WORKDIR /app1 unmodified lineCOPY requirements.txt /app/requirements.txtRUN pip install --no-cache-dir -r /app/requirements.txt# ---- Copy backend ----COPY api/ /app/api/# ---- Copy built frontend dist from Stage 1 ----# server.py expects WEB_DIST = ../web/dist relative to /app/api# so we must place it at /app/web/distCOPY --from=web_builder /web/dist /app/web/dist# ---- Run API (serves web dist too) ----EXPOSE 7860CMD ["uvicorn", "api.server:app", "--host", "0.0.0.0", "--port", "7860"]12345678910111213141516171 unmodified line19202122232425262728293031# =========================# 1) Web build stage# =========================FROM node:20-slim AS web_builderWORKDIR /webCOPY web/package*.json ./RUN npm installCOPY web/ ./RUN npm run build # -> outputs /web/build (per your log)# =========================# 2) API runtime stage# =========================FROM python:3.11-slimWORKDIR /app1 unmodified lineCOPY requirements.txt /app/requirements.txtRUN pip install --no-cache-dir -r /app/requirements.txt# ---- Copy API source ----COPY api/ /app/api/# ---- Copy built web assets ----COPY --from=web_builder /web/build /app/web/build# ---- Run API (serves web build too) ----ENV PORT=7860EXPOSE 7860CMD ["uvicorn", "api.server:app", "--host", "0.0.0.0", "--port", "7860"]
Dockerfile+11-25