Skip to content

Update check.yml

Update check.yml #12

Workflow file for this run

name: CI
on:
workflow_dispatch:
push:
branches:
- main
jobs:
test-docker-pull:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Read and process dockerhub-proxy.md
id: read_file
run: |
# Read the file and process each line
urls=()
while IFS= read -r line; do
# Remove '- https://' prefix and append to urls array
url="${line/- https:\/\//}"
urls+=("$url")
done < docs/reference/_include/dockerhub-proxy.md
# Print the array for debugging
echo "Processed URLs: ${urls[@]}"
# Save the array to the outputs
echo "::set-output name=urls::${urls[*]}"
- name: Docker pull from proxies
run: |
# Read the URLs from the previous step
urls="${{ steps.read_file.outputs.urls }}"
IFS=' ' read -r -a url_array <<< "$urls"
# Define the size of the image in MB
image_size_mb=501
# Try to pull the image from each URL
for url in "${url_array[@]}"; do
echo "Trying to pull from $url/library/mysql:5.7"
# Get the start time
start_time=$(date +%s)
# Attempt to pull the image
if docker pull "$url/library/mysql:5.7"; then
# Get the end time
end_time=$(date +%s)
# Calculate the duration in seconds
duration=$((end_time - start_time))
# Calculate the pull rate in MB/s
if [ $duration -gt 0 ]; then
pull_rate=$(echo "scale=2; $image_size_mb / $duration" | bc)
else
pull_rate=0
fi
# Check if the pull rate is less than 1 MB/s
if (( $(echo "$pull_rate < 1" | bc -l) )); then
echo "Pull rate is less than 1 MB/s, marking as failure"
exit 1
else
echo "Successfully pulled from $url"
fi
# Delete the pulled image to ensure fresh pull for the next URL
docker rmi "$url/library/mysql:5.7"
else
echo "--------------Failed to pull from $url--------------"
pull_rate=0
fi
# Always check if the pull rate is less than 1 MB/s
if (( $(echo "$pull_rate < 1" | bc -l) )); then
echo "Pull rate is less than 1 MB/s, marking as failure"
exit 1
fi
echo "--------------Final pull rate($url): $pull_rate MB/s-------------"
done