forked from Websoft9/doc.websoft9.com
-
Notifications
You must be signed in to change notification settings - Fork 1
67 lines (53 loc) · 1.94 KB
/
check.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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