From 50508bedacc20e3f5548a31df1a80eaf6ee4f305 Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Tue, 21 Jul 2026 19:53:00 +0800 Subject: [PATCH] =?UTF-8?q?fix(worker):=20ffmpeg=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AE=8C=E6=95=B4=E6=80=A7=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?+=E5=A4=9A=E6=BA=90=E9=87=8D=E8=AF=95+=E5=9D=8F=E5=8C=85?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=B8=85=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题:johnvansickle.com偶尔返回损坏文件,buildx缓存命中坏包后反复失败 修复: 1. 下载后tar -tf校验完整性,损坏则删除缓存 2. 三源重试(主源+清华镜像+中科大镜像) 3. 最后验证ffmpeg/ffprobe二进制可执行 4. wget增加--tries=3 --timeout=30 --- infra/docker/worker.Dockerfile | 39 ++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/infra/docker/worker.Dockerfile b/infra/docker/worker.Dockerfile index 26f20d807..d7549fb28 100755 --- a/infra/docker/worker.Dockerfile +++ b/infra/docker/worker.Dockerfile @@ -25,17 +25,44 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ xz-utils \ && rm -rf /var/lib/apt/lists/* -# ---- 下载静态编译 ffmpeg(带缓存,避免每次重新下载)---- +# ---- 下载静态编译 ffmpeg(带缓存+完整性校验+多源重试)---- +# 问题背景:johnvansickle.com 偶尔返回损坏文件,缓存命中坏包后反复失败 +# 修复策略:1.三源下载 2.tar完整性校验 3.损坏删缓存重试 4.二进制可执行校验 RUN --mount=type=cache,target=/tmp/ffmpeg-cache,sharing=locked \ cd /tmp \ - && if [ ! -f /tmp/ffmpeg-cache/ffmpeg-release-amd64-static.tar.xz ]; then \ - wget -q -O /tmp/ffmpeg-cache/ffmpeg-release-amd64-static.tar.xz \ - https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz; \ - fi \ - && tar xf /tmp/ffmpeg-cache/ffmpeg-release-amd64-static.tar.xz \ + && FFMPEG_FILE="/tmp/ffmpeg-cache/ffmpeg-release-amd64-static.tar.xz" \ + && FFMPEG_SOURCES=( \ + "https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz" \ + "https://mirrors.tuna.tsinghua.edu.cn/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz" \ + "https://mirrors.ustc.edu.cn/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz" \ + ) \ + && download_ok=0 \ + && for src in "${FFMPEG_SOURCES[@]}"; do \ + if [ $download_ok -eq 0 ] && [ -f "$FFMPEG_FILE" ] && tar -tf "$FFMPEG_FILE" >/dev/null 2>&1; then \ + echo "[ffmpeg] cache valid, skip download"; \ + download_ok=1; \ + break; \ + fi; \ + rm -f "$FFMPEG_FILE"; \ + echo "[ffmpeg] downloading from $src"; \ + if wget -q --tries=3 --timeout=30 -O "$FFMPEG_FILE" "$src"; then \ + if tar -tf "$FFMPEG_FILE" >/dev/null 2>&1; then \ + echo "[ffmpeg] download OK, tar valid"; \ + download_ok=1; \ + break; \ + else \ + echo "[ffmpeg] corrupted file, removing cache"; \ + rm -f "$FFMPEG_FILE"; \ + fi; \ + fi; \ + done \ + && if [ $download_ok -eq 0 ]; then echo "[ffmpeg] ALL SOURCES FAILED"; exit 1; fi \ + && tar xf "$FFMPEG_FILE" \ && cp ffmpeg-*-amd64-static/ffmpeg /usr/local/bin/ffmpeg \ && cp ffmpeg-*-amd64-static/ffprobe /usr/local/bin/ffprobe \ && chmod +x /usr/local/bin/ffmpeg /usr/local/bin/ffprobe \ + && ffmpeg -version >/dev/null 2>&1 && ffprobe -version >/dev/null 2>&1 \ + && echo "[ffmpeg] binary valid" \ && rm -rf ffmpeg-* # ---- 安装 Python 依赖 ---- -- 2.54.0