perf: 前端路由级代码分割+资源长期缓存;后端列表查询封顶与N+1修复;Dockerfile将依赖烤入.venv根治升级崩溃

This commit is contained in:
qihu committed 2026-07-11 05:02:14 +08:00
1 parent f5968d0f61
commit 1346fbbd4b
6 files changed
+511 -756

No files matched your search

+33 -21
View File
@@ -2,8 +2,10 @@ FROM python:3.11-slim
WORKDIR /app
# 安装系统依赖(含编译bcrypt/cryptography所需的build-essential)
# Use Tsinghua mirror for faster downloads in China
# ============================================================
# 系统依赖(含编译 bcrypt/cryptography 所需的 build-essential)
# 使用清华镜像加速(国内环境)
# ============================================================
RUN sed -i 's|deb.debian.org|mirrors.tuna.tsinghua.edu.cn|g' /etc/apt/sources.list.d/debian.sources 2>/dev/null || true
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
@@ -17,23 +19,39 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
nginx \
&& rm -rf /var/lib/apt/lists/*
# 先复制依赖文件,利用 Docker 构建缓存
COPY backend/python/requirements.txt /app/backend/python/requirements.txt
COPY frontend/package.json /app/frontend/package.json
COPY frontend/package-lock.json /app/frontend/package-lock.json
# 安装Python依赖(build-essential/libffi-dev确保bcrypt/cryptography能编译)
RUN pip install --no-cache-dir -r /app/backend/python/requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
# 安装Node.js (用于前端构建) 并构建前端
# Use Tsinghua mirror for faster downloads in China
# ============================================================
# 安装 Node.js(用于前端构建)
# ============================================================
RUN sed -i 's|deb.debian.org|mirrors.tuna.tsinghua.edu.cn|g' /etc/apt/sources.list.d/debian.sources 2>/dev/null || true
RUN apt-get update && apt-get install -y --no-install-recommends \
nodejs \
npm \
&& rm -rf /var/lib/apt/lists/*
# ============================================================
# 复制项目源码
# ============================================================
COPY backend/ /app/backend/
COPY frontend/ /app/frontend/
COPY migrations/ /app/migrations/
COPY nginx.conf /app/nginx.conf
COPY VERSION /app/VERSION
COPY CHANGELOG.md /app/CHANGELOG.md
COPY run.sh /app/run.sh
# ============================================================
# 安装 Python 依赖到虚拟环境(与 run.sh 的 .venv 优先逻辑一致)
# 说明:run.sh 启动时会优先使用 $PYTHON_DIR/.venv,
# 此处把依赖直接烤进镜像的 .venv,避免运行时再联网安装导致崩溃循环。
# ============================================================
RUN python3 -m venv /app/backend/python/.venv && \
/app/backend/python/.venv/bin/pip install --no-cache-dir \
-r /app/backend/python/requirements.txt \
-i https://pypi.tuna.tsinghua.edu.cn/simple
# ============================================================
# 安装前端依赖并构建(使用国内 npm 镜像)
# ============================================================
RUN cd /app/frontend && npm install --registry=https://registry.npmmirror.com && npm run build
# 验证前端构建产物
@@ -41,15 +59,9 @@ RUN test -f /app/frontend/dist/index.html || (echo "ERROR: 前端构建失败,
RUN test -d /app/frontend/dist/assets || (echo "ERROR: 前端构建失败,assets 目录不存在" && exit 1)
RUN echo "前端构建完成,dist 目录大小: $(du -sh /app/frontend/dist | cut -f1)"
# 复制项目源码(排除前端源码,已单独构建)
COPY backend/ /app/backend/
COPY migrations/ /app/migrations/
COPY nginx.conf /app/nginx.conf
COPY VERSION /app/VERSION
COPY CHANGELOG.md /app/CHANGELOG.md
COPY run.sh /app/run.sh
# 配置nginx: 移除默认站点,写入自定义配置,确保日志目录权限
# ============================================================
# 配置 nginx:移除默认站点,写入自定义配置
# ============================================================
RUN rm -f /etc/nginx/sites-enabled/default && \
rm -f /etc/nginx/conf.d/default.conf 2>/dev/null || true; \
cp /app/nginx.conf /etc/nginx/conf.d/aiflow.conf && \