From f2c5997847012a349e9d5bcf6f1463cb623c82c5 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 24 Jan 2026 23:46:44 +0800 Subject: [PATCH] fix: use huggingface_hub for ONNX download and add CACHE_BUST - Use huggingface_hub.hf_hub_download() instead of curl (supports xet storage) - Add CACHE_BUST ARG to force fresh downloads after cache delete - Add font file size validation after download - Re-enable registry cache (buildcache tag deleted manually) - ARM64 graceful degradation for MinerU --- .github/workflows/release.yml | 7 ++++--- Dockerfile | 26 ++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e7663c3..328d20e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -155,6 +155,7 @@ jobs: # - 啟用 zstd compression 減少傳輸量和儲存空間 # - Multi-arch build 需要更多磁碟空間,已在上方清理 # - 明確指定 file: Dockerfile 避免與 Lite 版混淆 + # - 使用 CACHE_BUST 強制重新下載模型 # ======================================== - name: Build and push Docker image uses: docker/build-push-action@v6 @@ -166,15 +167,15 @@ jobs: ${{ env.DOCKER_IMAGE }}:${{ steps.tag.outputs.version }} ${{ env.DOCKER_IMAGE }}:latest platforms: linux/amd64,linux/arm64 - # 🔥 使用獨立的 cache key 避免與 Lite 版交叉污染 - # registry cache 沒有 10GB 限制,更適合大型模型 + # 使用 registry cache(已手動刪除 Docker Hub 上的 buildcache tag) cache-from: type=registry,ref=${{ env.DOCKER_IMAGE }}:buildcache-full cache-to: type=registry,ref=${{ env.DOCKER_IMAGE }}:buildcache-full,mode=max,compression=zstd # 啟用壓縮減少 image 大小 outputs: type=image,compression=zstd,compression-level=3 - # 設定 build 參數 + # 設定 build 參數(使用時間戳強制重新下載模型層) build-args: | BUILDKIT_INLINE_CACHE=1 + CACHE_BUST=${{ github.run_id }} - name: Docker Build Summary run: | diff --git a/Dockerfile b/Dockerfile index 012392c..0bbc857 100644 --- a/Dockerfile +++ b/Dockerfile @@ -392,7 +392,15 @@ ENV PDF_SIGN_REASON="ConvertX-CN PDF Packager" ENV PDF_SIGN_LOCATION="Taiwan" ENV PDF_SIGN_CONTACT="convertx-cn@localhost" -RUN set -eu && \ +# ============================================================================== +# 🔥 Cache Busting(強制重新執行模型下載層) +# ============================================================================== +# 當 CACHE_BUST 改變時,後續所有層都會重新執行 +# 這確保模型下載不會被損壞的 cache 跳過 +# ============================================================================== +ARG CACHE_BUST=1 +RUN echo "Cache bust: ${CACHE_BUST}" && \ + set -eu && \ echo "===========================================================" && \ echo "🚀 階段 12-UNIFIED:Python 工具 + 模型統一安裝" && \ echo "===========================================================" && \ @@ -453,7 +461,8 @@ RUN set -eu && \ echo "" && \ echo "📥 [6/8] 下載 PDFMathTranslate/BabelDOC DocLayout-YOLO ONNX 模型..." && \ mkdir -p /root/.cache/babeldoc/models && \ - python3 -c "from huggingface_hub import hf_hub_download; import shutil; import os; p=hf_hub_download(repo_id='wybxc/DocLayout-YOLO-DocStructBench-onnx', filename='doclayout_yolo_docstructbench_imgsz1024.onnx'); t='/root/.cache/babeldoc/models/doclayout_yolo_docstructbench_imgsz1024.onnx'; shutil.copy2(p, t); print(f'Downloaded and copied to {t}, size: {os.path.getsize(t)/1024/1024:.2f} MB')" && \ + echo " 正在下載 ONNX 模型(約 75MB)..." && \ + python3 -c "from huggingface_hub import hf_hub_download; import shutil, os, sys; print(' Downloading from HuggingFace...'); p=hf_hub_download(repo_id='wybxc/DocLayout-YOLO-DocStructBench-onnx', filename='doclayout_yolo_docstructbench_imgsz1024.onnx'); print(f' Downloaded to cache: {p}'); t='/root/.cache/babeldoc/models/doclayout_yolo_docstructbench_imgsz1024.onnx'; shutil.copy2(p, t); size=os.path.getsize(t); print(f' Copied to: {t}'); print(f' File size: {size} bytes ({size/1024/1024:.2f} MB)'); sys.exit(1) if size < 10000000 else print(' SUCCESS: ONNX model downloaded and verified')" && \ echo "✅ ONNX 模型下載完成" && \ ls -lh /root/.cache/babeldoc/models/*.onnx && \ \ @@ -483,6 +492,19 @@ RUN set -eu && \ "https://github.com/timelic/source-han-serif/releases/download/main/SourceHanSerifKR-Regular.ttf" && \ echo "✅ 字型下載完成" && \ ls -lh /app/*.ttf && \ + # 驗證字型檔案大小(確保下載完整) + echo " 驗證字型檔案..." && \ + for font in GoNotoKurrent-Regular.ttf SourceHanSerifCN-Regular.ttf SourceHanSerifTW-Regular.ttf SourceHanSerifJP-Regular.ttf SourceHanSerifKR-Regular.ttf; do \ + if [ ! -f "/app/$font" ]; then \ + echo " ERROR: Font not found: /app/$font" && exit 1; \ + fi; \ + size=$(stat -c%s "/app/$font" 2>/dev/null || stat -f%z "/app/$font" 2>/dev/null || echo 0); \ + if [ "$size" -lt 1000000 ]; then \ + echo " ERROR: Font too small: /app/$font ($size bytes)" && exit 1; \ + fi; \ + echo " ✓ $font ($size bytes)"; \ + done && \ + echo "✅ 所有字型驗證通過" && \ \ # ======================================== # [7/8] 下載 BabelDOC 完整資源