Skip to content

Commit 8a5a3b2

Browse files
committed
Add Docker login to Jenkins script to avoid rate limit issue
Enhance Jenkins pipeline by integrating Docker credentials for login to avoid rate limit issues Signed-off-by: Shuyang Xin <[email protected]>
1 parent 925f510 commit 8a5a3b2

File tree

5 files changed

+156
-6
lines changed

5 files changed

+156
-6
lines changed

ci/jenkins/docker_login.sh

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2024 Antrea Authors
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
DOCKER_REGISTRY=$(head -n1 "${WORKSPACE}/ci/docker-registry")
18+
19+
_usage="Usage: $0 [--docker-user <dockerUser>] [--docker-password <dockerPassword>]
20+
Run Docker login script.
21+
--docker-user Username for Docker account.
22+
--docker-password Password for Docker account.
23+
--registry The image registry to use."
24+
25+
while [[ $# -gt 0 ]]
26+
do
27+
key="$1"
28+
29+
case $key in
30+
--docker-user)
31+
DOCKER_USERNAME="$2"
32+
shift 2
33+
;;
34+
--docker-password)
35+
DOCKER_PASSWORD="$2"
36+
shift 2
37+
;;
38+
--registry)
39+
DOCKER_REGISTRY="$2"
40+
shift 2
41+
;;
42+
-h|--help)
43+
print_usage
44+
exit 0
45+
;;
46+
*) # unknown option
47+
echoerr "Unknown option $1"
48+
exit 1
49+
;;
50+
esac
51+
done
52+
53+
function docker_login() {
54+
set +ex
55+
for i in `seq 5`; do
56+
output=$(echo $2 | docker login --username=$1 --password-stdin 2>/dev/null)
57+
# Check if standard output contains "Login Succeeded"
58+
if [[ "$output" == *"Login Succeeded"* ]]; then
59+
echo "Docker login successful."
60+
break
61+
else
62+
sleep 5s
63+
echo "Docker login failed. Retrying"
64+
fi
65+
done
66+
set -ex
67+
}
68+
69+
# Exit if credentials are not set
70+
if [[ -z "$DOCKER_USERNAME" || -z "$DOCKER_PASSWORD" ]]; then
71+
echo "Error: Docker username or password not provided."
72+
exit 1
73+
fi
74+
75+
# Check if the registry is docker.io or any other acceptable registry
76+
if [[ "$DOCKER_REGISTRY" == "docker.io" ]]; then
77+
echo "Logging into Docker Hub..."
78+
docker_login "${DOCKER_USERNAME}" "${DOCKER_PASSWORD}"
79+
else
80+
echo "Registry $DOCKER_REGISTRY is not supported for login by this script."
81+
fi

ci/jenkins/jobs/macros.yaml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@
103103
#!/bin/bash
104104
set -ex
105105
DOCKER_REGISTRY="$(head -n1 ci/docker-registry)"
106-
./ci/jenkins/test-vmc.sh --cluster-name "$BUILD_TAG" --testcase e2e --coverage --codecov-token "${CODECOV_TOKEN}" --registry ${DOCKER_REGISTRY} --username "${CAPVC_USERNAME}" --password "${CAPVC_PASSWORD}"
106+
./ci/jenkins/docker_login.sh --docker-user ${{DOCKER_USERNAME}} --docker-password ${{DOCKER_PASSWORD}} --registry ${{DOCKER_REGISTRY}}
107+
./ci/jenkins/test-vmc.sh --cluster-name "$BUILD_TAG" --testcase e2e --coverage --codecov-token "${{CODECOV_TOKEN}}" --registry ${{DOCKER_REGISTRY}} --username "${{CAPVC_USERNAME}}" --password "${{CAPVC_PASSWORD}}"
107108
108109
- builder:
109110
name: builder-conformance
@@ -112,6 +113,7 @@
112113
#!/bin/bash
113114
set -ex
114115
DOCKER_REGISTRY="$(head -n1 ci/docker-registry)"
116+
./ci/jenkins/docker_login.sh --docker-user ${{DOCKER_USERNAME}} --docker-password ${{DOCKER_PASSWORD}} --registry ${{DOCKER_REGISTRY}}
115117
./ci/jenkins/test-vmc.sh --cluster-name "$BUILD_TAG" --testcase '{conformance_type}' --coverage --codecov-token "${{CODECOV_TOKEN}}" --registry ${{DOCKER_REGISTRY}} --username "${{CAPVC_USERNAME}}" --password "${{CAPVC_PASSWORD}}"
116118
117119
- builder:
@@ -128,6 +130,7 @@
128130
#!/bin/bash
129131
set -ex
130132
DOCKER_REGISTRY="$(head -n1 ci/docker-registry)"
133+
./ci/jenkins/docker_login.sh --docker-user ${{DOCKER_USERNAME}} --docker-password ${{DOCKER_PASSWORD}} --registry ${{DOCKER_REGISTRY}}
131134
./ci/jenkins/test.sh --testcase '{e2e_type}' --registry ${{DOCKER_REGISTRY}}
132135
133136
- builder:
@@ -137,6 +140,7 @@
137140
#!/bin/bash
138141
set -ex
139142
DOCKER_REGISTRY="$(head -n1 ci/docker-registry)"
143+
./ci/jenkins/docker_login.sh --docker-user ${{DOCKER_USERNAME}} --docker-password ${{DOCKER_PASSWORD}} --registry ${{DOCKER_REGISTRY}}
140144
./ci/jenkins/test.sh --testcase '{conformance_type}' --registry ${{DOCKER_REGISTRY}}
141145
142146
- builder:
@@ -146,7 +150,8 @@
146150
#!/bin/bash
147151
set -e
148152
DOCKER_REGISTRY="$(head -n1 ci/docker-registry)"
149-
./ci/jenkins/test.sh --testcase e2e --registry ${DOCKER_REGISTRY} --workdir "/home/ubuntu" --kubeconfig "/home/ubuntu/kube.conf" --testbed-type "flexible-ipam"
153+
./ci/jenkins/docker_login.sh --docker-user ${{DOCKER_USERNAME}} --docker-password ${{DOCKER_PASSWORD}} --registry ${{DOCKER_REGISTRY}}
154+
./ci/jenkins/test.sh --testcase e2e --registry ${{DOCKER_REGISTRY}} --workdir "/home/ubuntu" --kubeconfig "/home/ubuntu/kube.conf" --testbed-type "flexible-ipam"
150155
151156
- builder:
152157
name: builder-flow-visibility
@@ -208,6 +213,7 @@
208213
#!/bin/bash
209214
set -ex
210215
DOCKER_REGISTRY="$(head -n1 ci/docker-registry)"
216+
./ci/jenkins/docker_login.sh --docker-user ${{DOCKER_USERNAME}} --docker-password ${{DOCKER_PASSWORD}} --registry ${{DOCKER_REGISTRY}}
211217
KIND_TIMEOUT=135
212218
FULL_CLUSTER_NAME='{kind_cluster_name}'-"${{BUILD_NUMBER}}"
213219
# Delete all Kind clusters created more than 135 mins ago. 135 minutes is the timeout
@@ -231,6 +237,7 @@
231237
#!/bin/bash
232238
set -ex
233239
DOCKER_REGISTRY="$(head -n1 ci/docker-registry)"
240+
./ci/jenkins/docker_login.sh --docker-user ${{DOCKER_USERNAME}} --docker-password ${{DOCKER_PASSWORD}} --registry ${{DOCKER_REGISTRY}}
234241
KIND_TIMEOUT=135
235242
FULL_CLUSTER_NAME='{kind_cluster_name}'-"${{BUILD_NUMBER}}"
236243
# Delete all Kind clusters created more than 135 mins ago. 135 minutes is the timeout
@@ -273,7 +280,8 @@
273280
#!/bin/bash
274281
set -e
275282
DOCKER_REGISTRY="$(head -n1 ci/docker-registry)"
276-
./ci/jenkins/test-mc.sh --testcase e2e --registry ${DOCKER_REGISTRY} --mc-gateway --codecov-token "${CODECOV_TOKEN}" --coverage --kind
283+
./ci/jenkins/docker_login.sh --docker-user "${{DOCKER_USERNAME}}" --docker-password "${{DOCKER_PASSWORD}}" --registry ${{DOCKER_REGISTRY}}
284+
./ci/jenkins/test-mc.sh --testcase e2e --registry ${{DOCKER_REGISTRY}} --mc-gateway --codecov-token "${CODECOV_TOKEN}" --coverage --kind
277285
278286
- builder:
279287
name: builder-e2e-jumper
@@ -282,7 +290,8 @@
282290
#!/bin/bash
283291
set -e
284292
DOCKER_REGISTRY="$(head -n1 ci/docker-registry)"
285-
./ci/jenkins/test.sh --testcase e2e --registry ${DOCKER_REGISTRY} --testbed-type jumper
293+
./ci/jenkins/docker_login.sh --docker-user ${{DOCKER_USERNAME}} --docker-password ${{DOCKER_PASSWORD}} --registry ${{DOCKER_REGISTRY}}
294+
./ci/jenkins/test.sh --testcase e2e --registry ${{DOCKER_REGISTRY}} --testbed-type jumper
286295
287296
- builder:
288297
name: builder-conformance-jumper
@@ -291,6 +300,7 @@
291300
#!/bin/bash
292301
set -e
293302
DOCKER_REGISTRY="$(head -n1 ci/docker-registry)"
303+
./ci/jenkins/docker_login.sh --docker-user ${{DOCKER_USERNAME}} --docker-password ${{DOCKER_PASSWORD}} --registry ${{DOCKER_REGISTRY}}
294304
./ci/jenkins/test.sh --testcase '{conformance_type}' --registry ${{DOCKER_REGISTRY}} --testbed-type jumper
295305
296306
- builder:

ci/jenkins/jobs/projects-cloud.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@
9999
- text:
100100
credential-id: CAPVC_PASSWORD
101101
variable: CAPVC_PASSWORD
102+
- text:
103+
credential-id: DOCKER_USERNAME
104+
variable: DOCKER_USERNAME
105+
- text:
106+
credential-id: DOCKER_PASSWORD
107+
variable: DOCKER_PASSWORD
102108
publishers:
103109
- archive:
104110
allow-empty: true
@@ -211,6 +217,12 @@
211217
- text:
212218
credential-id: CAPVC_PASSWORD
213219
variable: CAPVC_PASSWORD
220+
- text:
221+
credential-id: DOCKER_USERNAME
222+
variable: DOCKER_USERNAME
223+
- text:
224+
credential-id: DOCKER_PASSWORD
225+
variable: DOCKER_PASSWORD
214226
publishers:
215227
- archive:
216228
allow-empty: true
@@ -310,6 +322,12 @@
310322
- text:
311323
credential-id: CAPVC_PASSWORD
312324
variable: CAPVC_PASSWORD
325+
- text:
326+
credential-id: DOCKER_USERNAME
327+
variable: DOCKER_USERNAME
328+
- text:
329+
credential-id: DOCKER_PASSWORD
330+
variable: DOCKER_PASSWORD
313331
publishers:
314332
- archive:
315333
allow-empty: true
@@ -397,6 +415,12 @@
397415
- text:
398416
credential-id: CAPVC_PASSWORD
399417
variable: CAPVC_PASSWORD
418+
- text:
419+
credential-id: DOCKER_USERNAME
420+
variable: DOCKER_USERNAME
421+
- text:
422+
credential-id: DOCKER_PASSWORD
423+
variable: DOCKER_PASSWORD
400424
publishers:
401425
- archive:
402426
allow-empty: true
@@ -509,6 +533,12 @@
509533
- text:
510534
credential-id: CAPVC_PASSWORD
511535
variable: CAPVC_PASSWORD
536+
- text:
537+
credential-id: DOCKER_USERNAME
538+
variable: DOCKER_USERNAME
539+
- text:
540+
credential-id: DOCKER_PASSWORD
541+
variable: DOCKER_PASSWORD
512542
publishers:
513543
- archive:
514544
allow-empty: true
@@ -580,6 +610,12 @@
580610
- text:
581611
credential-id: RESOURCEPOOLPATH
582612
variable: RESOURCEPOOLPATH
613+
- text:
614+
credential-id: DOCKER_USERNAME
615+
variable: DOCKER_USERNAME
616+
- text:
617+
credential-id: DOCKER_PASSWORD
618+
variable: DOCKER_PASSWORD
583619
- '{name}-{test_name}-for-gc':
584620
test_name: workload-cluster
585621
node: 'antrea-test-node'

ci/jenkins/jobs/projects-lab.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,12 @@
647647
- text:
648648
credential-id: GOVC_DATASTORE
649649
variable: GOVC_DATASTORE
650+
- text:
651+
credential-id: DOCKER_USERNAME
652+
variable: DOCKER_USERNAME
653+
- text:
654+
credential-id: DOCKER_PASSWORD
655+
variable: DOCKER_PASSWORD
650656
publishers:
651657
- archive:
652658
allow-empty: true
@@ -703,6 +709,12 @@
703709
- text:
704710
credential-id: GOVC_DATASTORE
705711
variable: GOVC_DATASTORE
712+
- text:
713+
credential-id: DOCKER_USERNAME
714+
variable: DOCKER_USERNAME
715+
- text:
716+
credential-id: DOCKER_PASSWORD
717+
variable: DOCKER_PASSWORD
706718
publishers:
707719
- archive:
708720
allow-empty: true
@@ -831,6 +843,12 @@
831843
- text:
832844
credential-id: GOVC_DATASTORE
833845
variable: GOVC_DATASTORE
846+
- text:
847+
credential-id: DOCKER_USERNAME
848+
variable: DOCKER_USERNAME
849+
- text:
850+
credential-id: DOCKER_PASSWORD
851+
variable: DOCKER_PASSWORD
834852
publishers:
835853
- archive:
836854
allow-empty: true
@@ -882,6 +900,12 @@
882900
- text:
883901
credential-id: GOVC_DATASTORE
884902
variable: GOVC_DATASTORE
903+
- text:
904+
credential-id: DOCKER_USERNAME
905+
variable: DOCKER_USERNAME
906+
- text:
907+
credential-id: DOCKER_PASSWORD
908+
variable: DOCKER_PASSWORD
885909
- '{name}-{test_name}-for-pull-request':
886910
test_name: kind-conformance
887911
node: 'antrea-kind-testbed'

ci/jenkins/test-vmc.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,14 +646,13 @@ function collect_coverage() {
646646
}
647647

648648
function cleanup_cluster() {
649+
release_static_ip
649650
echo "=== Cleaning up VMC cluster ${CLUSTER} ==="
650651
export KUBECONFIG=$KUBECONFIG_PATH
651652

652653
kubectl delete ns ${CLUSTER}
653654
rm -rf "${GIT_CHECKOUT_DIR}/jenkins"
654655
echo "=== Cleanup cluster ${CLUSTER} succeeded ==="
655-
656-
release_static_ip
657656
}
658657

659658
function garbage_collection() {

0 commit comments

Comments
 (0)