MirrorsProxy.Download

指南/CI 与脚本中使用加速

CI 与脚本中使用加速

在 Dockerfile、Shell 脚本、pip、go 等场景使用 GitHub 加速地址的写法与注意事项。

先记住三条原则

  1. 海外 CI runner(GitHub Actions 官方 runner 等)访问 GitHub 本来就快,不要加加速前缀
  2. 国内自建 runner、国内服务器脚本才使用镜像前缀
  3. 固定版本号优先于 latest(/releases/latest/download/ 依赖 302 跳转,部分节点无法跟随)

Dockerfile

RUN wget -qO src.tar.gz https://gh-proxy.com/https://github.com/user/repo/archive/refs/tags/v1.2.0.tar.gz \
 && tar -xzf src.tar.gz

pip

pip install git+https://gh-proxy.com/https://github.com/user/repo.git@v1.0.0

go 生态

go module 走 go get 协议,不适合 URL 前缀改写,直接换国内 module proxy:

go env -w GOPROXY=https://goproxy.cn,direct

脚本容错:多节点依次尝试

镜像可能失效,重要脚本建议准备多个地址依次回退:

URLS=(
  "https://gh-proxy.com/https://github.com/user/repo/releases/download/v1.0/app.zip"
  "https://ghproxy.vip/https://github.com/user/repo/releases/download/v1.0/app.zip"
)
for u in "${URLS[@]}"; do curl -fsLO "$u" && break; done

安全红线

私有仓库的 Release 资产需要带 token 下载,不要把 token 发给第三方镜像节点 —— 要么用官方渠道,要么自建 Worker(见《自建 Cloudflare Worker 加速节点》)。

← 返回转换工具