Skip to content

Commit 76ebb6b

Browse files
committed
feat(ci): add debugging about docker hub rate limits
1 parent b2f5772 commit 76ebb6b

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

.github/workflows/e2e.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ jobs:
151151
- name: Checkout repository
152152
uses: actions/checkout@v4
153153

154+
- name: Check Docker Hub rate limit
155+
run: |
156+
./hack/check-dockerhub-ratelimit.sh "${{ secrets.DOCKER_USERNAME }}" "${{ secrets.DOCKER_PASSWORD }}"
157+
154158
- name: Login to DockerHub
155159
uses: docker/login-action@v3
156160
with:
@@ -248,6 +252,10 @@ jobs:
248252
- name: Checkout repository
249253
uses: actions/checkout@v4
250254

255+
- name: Check Docker Hub rate limit
256+
run: |
257+
./hack/check-dockerhub-ratelimit.sh "${{ secrets.DOCKER_USERNAME }}" "${{ secrets.DOCKER_PASSWORD }}"
258+
251259
- name: Login to DockerHub
252260
uses: docker/login-action@v3
253261
with:
@@ -388,6 +396,10 @@ jobs:
388396
- name: Checkout repository
389397
uses: actions/checkout@v4
390398

399+
- name: Check Docker Hub rate limit
400+
run: |
401+
./hack/check-dockerhub-ratelimit.sh "${{ secrets.DOCKER_USERNAME }}" "${{ secrets.DOCKER_PASSWORD }}"
402+
391403
- name: Login to DockerHub
392404
uses: docker/login-action@v3
393405
with:

hack/check-dockerhub-ratelimit.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env bash
2+
3+
# Check if both LOGIN and PASSWORD are provided
4+
if [ -z "$1" ] || [ -z "$2" ]; then
5+
echo "Usage: $0 <LOGIN> <PASSWORD>"
6+
exit 1
7+
fi
8+
9+
LOGIN="$1"
10+
PASSWORD="$2"
11+
12+
# Check if curl is installed
13+
if ! command -v curl &> /dev/null; then
14+
echo "curl could not be found, please install it."
15+
exit 1
16+
fi
17+
18+
# Check if jq is installed
19+
if ! command -v jq &> /dev/null; then
20+
echo "jq could not be found, please install it."
21+
exit 1
22+
fi
23+
24+
# Fetch the token
25+
TOKEN=$(curl -s --user "$LOGIN:$PASSWORD" "https://auth.docker.io/token?service=registry.docker.io&scope=repository:ratelimitpreview/test:pull" | jq -r .token)
26+
27+
# Check if the token was successfully retrieved
28+
if [ -z "$TOKEN" ]; then
29+
echo "Failed to retrieve token. Please check your LOGIN and PASSWORD."
30+
exit 1
31+
fi
32+
33+
# Fetch the rate limit information
34+
RESPONSE=$(curl -s --head -H "Authorization: Bearer $TOKEN" https://registry-1.docker.io/v2/ratelimitpreview/test/manifests/latest)
35+
36+
# Check if the request was successful
37+
if [ -z "$RESPONSE" ]; then
38+
echo "Failed to fetch rate limit information."
39+
exit 1
40+
fi
41+
42+
# Check for rate limit headers
43+
RATELIMIT_LIMIT=$(echo "$RESPONSE" | grep -i "ratelimit-limit" || true)
44+
RATELIMIT_REMAINING=$(echo "$RESPONSE" | grep -i "ratelimit-remaining" || true)
45+
46+
# Display the rate limit information
47+
if [ -n "$RATELIMIT_LIMIT" ] || [ -n "$RATELIMIT_REMAINING" ]; then
48+
echo "Rate Limit Information:"
49+
echo "$RATELIMIT_LIMIT"
50+
echo "$RATELIMIT_REMAINING"
51+
else
52+
echo "No rate limit information found in the response. This might be a business account or the headers are not exposed."
53+
echo "Full response headers for debugging:"
54+
echo "$RESPONSE"
55+
fi

0 commit comments

Comments
 (0)