fix(worker): ffmpeg下载增加完整性校验+多源重试+坏包自动清缓存 #686
@@ -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 依赖 ----
|
||||
|
||||
Reference in New Issue
Block a user