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 52473a1
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/test-mirrors.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
- 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
image="library/nginx:1.25.1-alpine"
for registry in $registries
do
echo "Testing $registry"
# 清理可能存在的镜像
docker rmi "$registry/$image" > /dev/null 2>&1 || true
# 使用子shell隔离每个registry的执行
(
# 使用 timeout 命令限制执行时间
output=$(mktemp)
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//')
# 计算镜像大小(单位:MB)
image_size=$(docker image inspect "$registry/$image" --format='{{.Size}}' | awk '{print $1/1024/1024}')
# 计算速度(MB/s)
speed=$(echo "scale=2; $image_size / $pull_time" | bc)
echo "$registry is good, Speed: ${speed} MB/s, Time: ${pull_time}s"
else
status="❌ Failed"
speed="-"
pull_time="-"
echo "$registry failed"
fi
update_readme "$registry" "$status" "${speed} MB/s" "${pull_time}s"
docker rmi "$registry/$image" > /dev/null 2>&1 || true
rm "$output"
) || true # 即使子shell失败,也继续执行下一个registry
done
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
| Registry | Status | Speed | Time |
|----------|--------|-------|------|
| registry-1.docker.io | | | |
| hub.rat.dev | | | |
| docker.m.daocloud.io | | | |

0 comments on commit 52473a1

Please sign in to comment.