lework 5 years ago
parent
commit
c51555caff
  1. 44
      shell/docker_hub_speed_test.sh

44
shell/docker_hub_speed_test.sh

@ -33,8 +33,40 @@ mirrors=( @@ -33,8 +33,40 @@ mirrors=(
# function
######################################################################################################
function shutdown() {
tput cnorm # reset cursor
ps -ef | grep "$0" | awk '{print $2}' | xargs kill -9 '{}' >/dev/null 2>&1
}
trap shutdown EXIT
function spinner() {
# make sure we use non-unicode character type locale
# (that way it works for any locale as long as the font supports the characters)
local LC_CTYPE=C
speed_test "$@" &
sleep 1
local pid=$(ps -ef | grep -E '[w]get.*-4O /dev/null -T300' | awk '{print $2}') # Process Id of the previous running command
local spin='◐◓◑◒'
local charwidth=3
local i=0
tput civis # cursor invisible
while kill -0 $pid 2>/dev/null; do
local i=$(((i + $charwidth) % ${#spin}))
printf "%s" "${spin:$i:$charwidth}"
echo -en "\033[1D"
sleep .1
done
tput cnorm
wait
}
speed_test() {
local output=$(LANG=C wget --header="$3" -4O /dev/null -T300 "$1" 2>&1)
local output=$(LANG=C wget ${3:+"--header="}"$3" -4O /dev/null -T300 "$1" 2>&1)
local speed=$(printf '%s' "$output" | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}')
local ipaddress=$(printf '%s' "$output" | awk -F'|' '/Connecting to .*\|([^\|]+)\|/ {print $2}'| tail -1)
local time=$(printf '%s' "$output" | awk -F= '/100% / {print $2}')
@ -62,7 +94,7 @@ echo -e "\n\nDocker Hub mirror site speed test" @@ -62,7 +94,7 @@ echo -e "\n\nDocker Hub mirror site speed test"
echo -e "\n[Mirror Site]"
for mirror in ${!mirrors[*]}; do
printf "${PLAIN}%-14s${GREEN}%-20s${PLAIN}\n" ${mirror} ": ${mirrors[$mirror]}"
printf "${PLAIN}%-14s${GREEN}%-20s${PLAIN}\n" ${mirror} ": ${mirrors[$mirror]}"
done
printf "${PLAIN}%-14s${GREEN}%-20s${PLAIN}\n" "docker" ": https://registry-1.docker.io"
@ -71,7 +103,7 @@ echo -e "Test Image : ${YELLOW}${image_name}:${image_tag}${PLAIN}" @@ -71,7 +103,7 @@ echo -e "Test Image : ${YELLOW}${image_name}:${image_tag}${PLAIN}"
docker_token=$(curl -fsSL "https://auth.docker.io/token?service=registry.docker.io&scope=repository:${image_name}:pull" | awk '-F"' '{print $4}')
image_manifests=$(curl -fsSL -H "Authorization: Bearer ${docker_token}" "https://registry-1.docker.io/v2/${image_name}/manifests/${image_tag}" | awk -F'"' '/"blobSum":/ {print $4}')
image_layer=$( echo $image_manifests | tr ' ' '\n' | sort -u| head -1 )
image_layer=$(echo $image_manifests | tr ' ' '\n' | sort -u| head -1)
echo -e "Download layer : ${YELLOW}${image_layer}${PLAIN}\n"
printf "%-14s%-20s%-14s%-20s%-14s\n" "Site Name" "IPv4 address" "File Size" "Download Time" "Download Speed"
@ -80,7 +112,9 @@ for mirror in ${!mirrors[*]}; do @@ -80,7 +112,9 @@ for mirror in ${!mirrors[*]}; do
image_manifests=$(curl -s "${mirror}/v2/library/${image_name}/manifests/${image_tag}" | awk -F'"' '/"blobSum":/ {print $4}')
image_layer=$( echo $resp | tr ' ' '\n' | sort -u | head -1)
fi
speed_test "${mirrors[$mirror]}/v2/${image_name}/blobs/${image_layer}" ${mirror}
spinner "${mirrors[$mirror]}/v2/${image_name}/blobs/${image_layer}" ${mirror}
done
speed_test "https://registry-1.docker.io/v2/${image_name}/blobs/${image_layer}" "docker" "Authorization: Bearer $docker_token"
spinner "https://registry-1.docker.io/v2/${image_name}/blobs/${image_layer}" "docker" "Authorization: Bearer $docker_token"
echo

Loading…
Cancel
Save