Skip to content

Update check.yml

Update check.yml #5

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: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Pull Docker image with timeout and measure speed
run: |
echo "Pulling Docker image with timeout..."
# Set the maximum time (in seconds) for pulling the image
TIMEOUT_DURATION=5
IMAGE_NAME=docker.rainbond.cc/library/mysql:5.6
# Start pulling the image in the background
(
docker pull $IMAGE_NAME 2>&1 &
echo $! > pull_pid.txt
) | tee pull_output.log &
PULL_PID=$(cat pull_pid.txt)
# Wait for the specified duration
sleep $TIMEOUT_DURATION
# Kill the docker pull process after the timeout
kill $PULL_PID
# Calculate the duration
START_TIME=$(date +%s -r pull_output.log)
END_TIME=$(date +%s)
DURATION=$((END_TIME - START_TIME))
# Parse the output to find the downloaded size
DOWNLOADED_SIZE=$(grep -oP 'Downloaded \K[0-9]+(?=MB)' pull_output.log | tail -1)
# Calculate the average speed (MB/s)
if [ -n "$DOWNLOADED_SIZE" ] && [ "$DURATION" -gt 0 ]; then
AVERAGE_SPEED=$(echo "scale=2; $DOWNLOADED_SIZE / $DURATION" | bc)
echo "Downloaded size: $DOWNLOADED_SIZE MB"
echo "Duration: $DURATION seconds"
echo "Average speed: $AVERAGE_SPEED MB/s"
# Check if the average speed is less than 1 MB/s
if (( $(echo "$AVERAGE_SPEED < 1" | bc -l) )); then
echo "Download speed is below 1 MB/s, which is not acceptable."
else
echo "Download speed is acceptable."
fi
else
echo "Failed to calculate the average speed."
fi
- name: Check Docker images
run: docker images