Skip to content

feat: test mirrors

feat: test mirrors #5

Workflow file for this run

name: Test Registry
on:
push:
schedule:
- cron: '0 0 */1 * *'
workflow_dispatch:
jobs:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: docker-practice/actions-setup-docker@master
with:
docker_buildx: false
- run: docker version
- run: docker info
- 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 "/| $registry |/ s/|.*$/| $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
# 使用 time 命令测量拉取时间,同时捕获输出以计算速度
output=$(mktemp)
{ time docker pull "$registry/$image" > "$output" 2>&1; } 2> time_output
if [ $? -eq 0 ]; then
status="✅ Good"
# 提取实际时间(单位:秒)
pull_time=$(grep real time_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="❌ Outdated"
speed="-"
pull_time="-"
echo "$registry is outdated"
fi
update_readme "$registry" "$status" "${speed} MB/s" "${pull_time}s"
docker rmi "$registry/$image" > /dev/null 2>&1 || true
rm "$output" time_output
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 README with latest registry test results"; git push)