优化静态路由

This commit is contained in:
Sakurasan
2026-07-07 16:07:10 +08:00
parent 0ba7952082
commit 62961017ea
3 changed files with 34 additions and 21 deletions
+15 -8
View File
@@ -1,4 +1,4 @@
# ---- Frontend build (仅构建机原生架构编译一次) ----
# ---- Frontend build ----
FROM --platform=$BUILDPLATFORM node:22-alpine AS frontend-build
WORKDIR /app
COPY package.json pnpm-lock.yaml .npmrc ./
@@ -6,18 +6,25 @@ RUN corepack enable && corepack prepare pnpm@10 --activate && pnpm install
COPY . .
RUN pnpm build
# ---- Backend runtime ----
# ---- Python deps build(带 gcc 编译,产物仅用于复制)----
FROM python:3.11-slim AS python-deps
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends gcc \
&& rm -rf /var/lib/apt/lists/*
COPY backend/requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# 删除字节码缓存,减小体积
RUN find /usr/local/lib/python3.11 -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
# ---- Final runtime ----
FROM python:3.11-slim
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends gcc \
&& rm -rf /var/lib/apt/lists/*
COPY backend/requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# 仅复制已编译好的包,无需 gcc
COPY --from=python-deps /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
COPY backend/ .
COPY --from=frontend-build /app/dist ./dist
EXPOSE 8000
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
CMD ["python", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]