优化 Docker Compose 下载:添加多个国内镜像源备份
Some checks failed
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Failing after 3m54s

- 添加 5 个国内镜像源自动切换(ghproxy.net、gh-proxy.com 等)
- 每个源 15 秒连接超时、60 秒下载超时
- 循环尝试,任一成功即停止
- 所有国内源失败后才使用官方源(300 秒超时)
- 显示每个源的尝试状态,便于调试
This commit is contained in:
2026-01-20 09:59:55 +08:00
parent 0584a474cc
commit 90ecfce8c5

View File

@@ -29,13 +29,31 @@ jobs:
# 创建插件目录
mkdir -p ~/.docker/cli-plugins/
# 尝试从国内镜像下载(更快
echo "尝试从国内镜像下载..."
if curl -fSL --connect-timeout 10 https://mirror.ghproxy.com/https://github.com/docker/compose/releases/download/v2.24.5/docker-compose-linux-x86_64 -o ~/.docker/cli-plugins/docker-compose 2>/dev/null; then
echo "✅ 从国内镜像下载成功"
else
echo "⚠️ 国内镜像失败,尝试官方源..."
curl -fSL https://github.com/docker/compose/releases/download/v2.24.5/docker-compose-linux-x86_64 -o ~/.docker/cli-plugins/docker-compose
# 定义多个国内镜像源(按顺序尝试)
MIRRORS=(
"https://ghproxy.net/https://github.com/docker/compose/releases/download/v2.24.5/docker-compose-linux-x86_64"
"https://gh-proxy.com/https://github.com/docker/compose/releases/download/v2.24.5/docker-compose-linux-x86_64"
"https://ghps.cc/https://github.com/docker/compose/releases/download/v2.24.5/docker-compose-linux-x86_64"
"https://github.moeyy.xyz/https://github.com/docker/compose/releases/download/v2.24.5/docker-compose-linux-x86_64"
"https://mirror.ghproxy.com/https://github.com/docker/compose/releases/download/v2.24.5/docker-compose-linux-x86_64"
)
DOWNLOADED=false
for MIRROR in "${MIRRORS[@]}"; do
echo "🔄 尝试: $(echo $MIRROR | cut -d'/' -f3)"
if curl -fSL --connect-timeout 15 --max-time 60 "$MIRROR" -o ~/.docker/cli-plugins/docker-compose 2>/dev/null; then
echo "✅ 下载成功"
DOWNLOADED=true
break
else
echo "❌ 失败,尝试下一个..."
fi
done
# 如果所有国内镜像都失败,尝试官方源
if [ "$DOWNLOADED" = false ]; then
echo "⚠️ 所有国内镜像失败,尝试官方源(可能较慢)..."
curl -fSL --connect-timeout 30 --max-time 300 https://github.com/docker/compose/releases/download/v2.24.5/docker-compose-linux-x86_64 -o ~/.docker/cli-plugins/docker-compose
fi
chmod +x ~/.docker/cli-plugins/docker-compose