🔀 合并 FileCodeBox 2.5.4 安全更新

同步官方 2.5.4 的初始化、安全、容量控制与上传校验,并保留 2026 主题、动态资源缓存和管理后台统计能力。

- 使用原子领取和容量预留,补齐文件校验、限流、令牌轮换与路径防护
- 保留三主题构建、2026 静态资源隔离及 TransferStats 生命周期记录
- 已通过容器生产镜像构建、23 项安全与分享回归测试、Python 编译检查和 Dockerfile 检查
This commit is contained in:
orion committed 2026-08-07 09:09:42 +08:00
commit 0be5a31a59
121 files changed
+5302 -34718

No files matched your search

+35 -10
View File
@@ -1,5 +1,9 @@
# 第一阶段:构建前端主题
FROM node:20-alpine AS frontend-builder
# 前端产物与 CPU 架构无关,使用原生构建平台避免在 QEMU 中运行 Node/pnpm。
FROM --platform=$BUILDPLATFORM node:20-alpine AS frontend-builder
ARG FRONTEND_2024_REF=main
ARG FRONTEND_2023_REF=main
RUN apk add --no-cache git python3 make g++
@@ -13,38 +17,53 @@ ARG FRONTEND_2024_REPO=https://git.orionc.me/orion/FileCodeBoxFronted.git
ARG FRONTEND_2024_BRANCH=main
ARG FRONTEND_CACHE_BUST=1
RUN echo "$FRONTEND_CACHE_BUST" >/tmp/frontend-cache-bust && \
git clone --depth 1 --branch "$FRONTEND_2024_BRANCH" "$FRONTEND_2024_REPO" /build/fronted-2024 && \
git clone --filter=blob:none --no-checkout "$FRONTEND_2024_REPO" /build/fronted-2024 && \
cd /build/fronted-2024 && \
git fetch --depth 1 origin "${FRONTEND_2024_REF}" && \
git checkout --detach FETCH_HEAD && \
pnpm install --frozen-lockfile --prod=false && \
pnpm run build
VITE_GIT_COMMIT="$(git rev-parse HEAD)" pnpm run build
# 克隆并构建 2026 主题
# 克隆并构建定制 2026 主题
ARG FRONTEND_2026_REPO=https://git.orionc.me/orion/FileCodeBoxFronted2026.git
ARG FRONTEND_2026_BRANCH=test/custom-admin-ui
RUN echo "$FRONTEND_CACHE_BUST" >/tmp/frontend-2026-cache-bust && \
git clone --depth 1 --branch "$FRONTEND_2026_BRANCH" "$FRONTEND_2026_REPO" /build/fronted-2026 && \
cd /build/fronted-2026 && \
pnpm install --frozen-lockfile --prod=false && \
pnpm run build
VITE_GIT_COMMIT="$(git rev-parse HEAD)" pnpm run build
# 克隆并构建 2023 主题
ARG FRONTEND_2023_REPO=https://git.orionc.me/orion/FileCodeBoxFronted2023.git
ARG FRONTEND_2023_BRANCH=main
RUN git clone --depth 1 --branch "$FRONTEND_2023_BRANCH" "$FRONTEND_2023_REPO" /build/fronted-2023 && \
RUN git clone --filter=blob:none --no-checkout "$FRONTEND_2023_REPO" /build/fronted-2023 && \
cd /build/fronted-2023 && \
git fetch --depth 1 origin "${FRONTEND_2023_REF}" && \
git checkout --detach FETCH_HEAD && \
npm install --legacy-peer-deps && \
npm run build
# 第二阶段:构建最终镜像
FROM python:3.12-slim-bookworm
ARG APP_VERSION
ARG VCS_REF=unknown
ARG FRONTEND_2024_REF=main
ARG FRONTEND_2023_REF=main
LABEL author="Lan"
LABEL email="xzu@live.com"
LABEL org.opencontainers.image.version="${APP_VERSION}"
LABEL org.opencontainers.image.revision="${VCS_REF}"
LABEL org.opencontainers.image.filecodebox.frontend-2024-revision="${FRONTEND_2024_REF}"
LABEL org.opencontainers.image.filecodebox.frontend-2023-revision="${FRONTEND_2023_REF}"
WORKDIR /app
# 复制项目文件(通过 .dockerignore 排除不必要的文件)
COPY . .
# 分支镜像使用带提交号的开发版本;正式镜像使用 VERSION 中的版本。
ENV APP_VERSION="${APP_VERSION}"
# 设置时区
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo 'Asia/Shanghai' > /etc/timezone
@@ -54,17 +73,23 @@ COPY --from=frontend-builder /build/fronted-2024/dist ./themes/2024
COPY --from=frontend-builder /build/fronted-2026/dist ./themes/2026
COPY --from=frontend-builder /build/fronted-2023/dist ./themes/2023
# 安装系统安全更新 + Python 依赖
RUN apt-get update \
&& apt-get upgrade -y --no-install-recommends \
&& rm -rf /var/lib/apt/lists/* \
&& pip install --no-cache-dir -r requirements.txt \
&& pip cache purge || true
# 安装 Python 依赖
RUN pip install --no-cache-dir -r requirements.txt
# 环境变量配置
ENV HOST="0.0.0.0" \
PORT=12345 \
WORKERS=1 \
LOG_LEVEL="info"
LOG_LEVEL="info" \
FORWARDED_ALLOW_IPS=""
EXPOSE 12345
# 生产环境启动命令
CMD ["sh", "-c", "exec uvicorn main:app --host \"$HOST\" --port \"$PORT\" --workers \"$WORKERS\" --log-level \"$LOG_LEVEL\" --proxy-headers --forwarded-allow-ips '*'"]
# FORWARDED_ALLOW_IPS 由部署环境显式指定,避免任意客户端伪造 X-Forwarded-*。
CMD ["sh", "-c", "exec uvicorn main:app --host \"$HOST\" --port \"$PORT\" --workers \"$WORKERS\" --log-level \"$LOG_LEVEL\" --proxy-headers --forwarded-allow-ips \"${FORWARDED_ALLOW_IPS:-}\""]