Skip to content

Commit

Permalink
feat: test mirrors
Browse files Browse the repository at this point in the history
  • Loading branch information
Loonphy authored and Loonphy committed Sep 25, 2024
0 parents commit 733e8d1
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/test-mirrors.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Test Registry

on:
push:
schedule:
- cron: '0 0 */1 * *'
workflow_dispatch:

jobs:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Test Registries and Update README
run: |
# 读取 README.md 中的 registry 列表
registries=$(awk '/\| Registry \| Status \| Speed \| Time \|/,/^$/' README.md | tail -n +3 | sed '/^$/d' | awk -F'|' '{print $2}' | sed 's/^ *//;s/ *$//')
# 更新 README.md 的函数
update_readme() {
local registry="$1"
local status="$2"
local speed="$3"
local time="$4"
sed -i "s#| $registry |.*#| $registry | $status | $speed | $time |#" README.md
}
# 测试 registry 的函数,包含重试逻辑
test_registry() {
local registry="$1"
local image="$2"
local max_attempts=3
local attempt=1
local output=$(mktemp)
while [ $attempt -le $max_attempts ]; do
echo "Attempt $attempt of $max_attempts for $registry"
if timeout 60s bash -c "time docker pull $registry/$image" > "$output" 2>&1; then
status="✅ Good"
pull_time=$(grep real "$output" | awk '{print $2}' | sed 's/0m//;s/s//')
image_size=$(docker image inspect "$registry/$image" --format='{{.Size}}' | awk '{print $1/1024/1024}')
speed=$(echo "scale=2; $image_size / $pull_time" | bc)
echo "$registry is good, Speed: ${speed} MB/s, Time: ${pull_time}s"
update_readme "$registry" "$status" "${speed} MB/s" "${pull_time}s"
rm "$output"
return 0
else
echo "$registry failed on attempt $attempt"
attempt=$((attempt + 1))
sleep 5 # 等待5秒后重试
fi
done
status="❌ Failed"
update_readme "$registry" "$status" "-" "-"
rm "$output"
return 1
}
# 测试每个 registry
image="library/nginx:alpine"
for registry in $registries
do
echo "Testing $registry"
# 清理可能存在的镜像
docker rmi "$registry/$image" > /dev/null 2>&1 || true
# 使用子shell隔离每个registry的执行
(
test_registry "$registry" "$image"
docker rmi "$registry/$image" > /dev/null 2>&1 || true
) || true # 即使子shell失败,也继续执行下一个registry
done
- name: Commit and push if changed
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git add README.md
git diff --quiet && git diff --staged --quiet || (git commit -m "update registry test results"; git push)
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Docker 镜像测速

## Why

因为众所周知的原因,国内访问 Docker Hub 的速度非常慢。广大热心网友贡献了大量的镜像加速服务,但是速度参差不齐。


所以该项目旨在罗列互联网上分享的镜像地址,并生成测速结果。

> [!WARNING] 注意
> 测速利用 GitHub Actions,服务器托管在国外,因此测速结果中的速度快不代表国内拉取快。
>
本项目尽量保证罗列的镜像地址可用。

## 测速结果

| Registry | Status | Speed | Time |
|----------|--------|-------|------|
| hub.rat.dev | | | |
| docker.m.daocloud.io | | | |

0 comments on commit 733e8d1

Please sign in to comment.