Mantain mirror (#795)

This commit is contained in:
Shiming Zhang 2023-11-10 17:44:41 +08:00 committed by GitHub
parent 45aee54e98
commit b20b9daf42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 77 additions and 21 deletions

View File

@ -33,7 +33,16 @@ jobs:
gh pr comment "${{ github.event.pull_request.number }}" --body '请运行 `./hack/fmt.sh domain.txt` 对内容进行排序'
exit 1
}
- name: Verify mirror.txt
- name: Verify mirror.txt image
run: |
./hack/verify-fmt-image.sh mirror.txt || {
echo "Please run './hack/fmt-image.sh mirror.txt'"
gh pr comment "${{ github.event.pull_request.number }}" --body '请运行 `./hack/fmt-image.sh mirror.txt` 对内容进行格式化'
exit 1
}
- name: Verify mirror.txt sort
run: |
./hack/verify-fmt.sh mirror.txt || {
echo "Please run './hack/fmt.sh mirror.txt'"

25
hack/fmt-image.sh Executable file
View File

@ -0,0 +1,25 @@
#!/usr/bin/env bash
function filter_docker_library() {
while read -r line; do
if [[ $line =~ ^docker\.io/[^/]*$ ]]; then
echo "docker.io/library/${line#docker.io/}"
else
echo "${line}"
fi
done
}
function filter_k8s_old() {
while read -r line; do
if [[ $line =~ ^k8s\.gcr\.io/.*$ ]]; then
echo "registry.k8s.io/${line#k8s.gcr.io/}"
else
echo "${line}"
fi
done
}
cat $1 |
filter_docker_library |
filter_k8s_old >$1.tmp && mv $1.tmp $1

View File

@ -2,26 +2,6 @@
export LC_ALL=C
function filter_docker_library() {
while read -r line; do
if [[ $line =~ ^docker\.io/[^/]*$ ]]; then
echo "docker.io/library/${line#docker.io/}"
else
echo "${line}"
fi
done
}
function filter_k8s_old() {
while read -r line; do
if [[ $line =~ ^k8s\.gcr\.io/.*$ ]]; then
echo "registry.k8s.io/${line#k8s.gcr.io/}"
else
echo "${line}"
fi
done
}
cat $1 |
filter_docker_library |
filter_k8s_old |

33
hack/merge-mirror.sh Executable file
View File

@ -0,0 +1,33 @@
#!/usr/bin/env bash
base_list="${1}"
used_list="${2}"
used_top="${3:-100}"
function used_top() {
cat "${used_list}" | head -n "${used_top}"
}
function intersection_used() {
sort "${base_list}" "${used_list}" | uniq -d
}
function fixed_docker() {
grep "^docker\.io/library/" "${base_list}"
grep "^docker\.io/library/" "${used_list}"
}
function fixed_k8s() {
grep "^registry\.k8s\.io/" "${base_list}"
grep "^registry\.k8s\.io/" "${used_list}"
}
function fixed_istio() {
grep "^docker\.io/istio/" "${base_list}"
grep "^docker\.io/istio/" "${used_list}"
}
cat <(used_top) \
<(intersection_used) \
<(fixed_docker) \
<(fixed_k8s) | sort | uniq -u

9
hack/verify-fmt-image.sh Executable file
View File

@ -0,0 +1,9 @@
#!/usr/bin/env bash
export LC_ALL=C
cp $1 $1.bak
$(dirname "${BASH_SOURCE}")/fmt-image.sh $1.bak
diff -c $1 $1.bak && rm $1.bak