From 364fede1b25dbbab7bd02a633809bc7d2b37d668 Mon Sep 17 00:00:00 2001 From: kplam Date: Sat, 1 Aug 2026 21:48:41 +0800 Subject: [PATCH] =?UTF-8?q?build:=20=E7=B2=BE=E7=AE=80=20Dockerfile?= =?UTF-8?q?=EF=BC=8C=E7=A7=BB=E9=99=A4=E9=95=9C=E5=83=8F=E5=86=85=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E6=9E=84=E5=BB=BA=E9=98=B6=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 前端采用挂载式部署(compose 将 ./frontend/dist 挂到 /app/app/static/admin), 镜像内烘焙前端纯属冗余且导致 NAS 构建时 npm ci 访问 registry 失败。 改为镜像只负责 Python 运行时+依赖,前端由本地 npm run build 后 rsync。 --- Dockerfile | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index d8e9a9a..ee4378b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,10 @@ -# ---------- Stage 1: 前端构建 ---------- -FROM node:20-slim AS frontend-builder - -WORKDIR /frontend - -# 依赖层(利用 Docker 层缓存) -COPY frontend/package.json frontend/package-lock.json ./ -RUN npm ci - -# 源码 + 构建 -COPY frontend/ ./ -RUN npm run build - -# ---------- Stage 2: Python 后端 ---------- +# ---------- Python 后端运行时镜像 ---------- +# 部署模型说明: +# 前端采用「挂载式」部署——docker-compose 将宿主机的 ./frontend/dist +# 挂到容器的 /app/app/static/admin,运行时直接覆盖镜像内同名目录。 +# 因此镜像【不再构建前端】,只负责 Python 运行时 + 依赖;前端由本地 +# `npm run build` 后 rsync 到 NAS,或挂载既有 dist。 +# 仅当 pyproject.toml / uv.lock 变化时才需 `docker build -t qmdsearch-app .` 一次。 FROM python:3.12-slim AS base WORKDIR /app @@ -19,7 +12,7 @@ WORKDIR /app # 安装 uv(放到 PATH 中,供 uv sync 与 CMD 的 uv run 使用) COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv -# 依赖层 +# 依赖层(利用 Docker 层缓存) COPY pyproject.toml uv.lock ./ RUN uv sync --frozen --no-dev @@ -27,9 +20,6 @@ RUN uv sync --frozen --no-dev COPY app/ app/ COPY scripts/ scripts/ -# 前端构建产物 → 后端静态目录(SPA 由 /admin 路由服务) -COPY --from=frontend-builder /frontend/dist /app/app/static/admin - EXPOSE 8000 HEALTHCHECK --interval=30s --timeout=5s --retries=3 \