Skip to content

Commit f7cce73

Browse files
Add Docker login to Jenkins script to avoid rate limit issue (#6368)
* 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]> * Fix some issues in docker_login.sh Signed-off-by: Antonin Bas <[email protected]> --------- Signed-off-by: Shuyang Xin <[email protected]> Signed-off-by: Antonin Bas <[email protected]> Co-authored-by: Antonin Bas <[email protected]>
1 parent b3ef929 commit f7cce73

File tree

5 files changed

+158
-6
lines changed

5 files changed

+158
-6
lines changed

ci/jenkins/docker_login.sh

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
function echoerr {
18+
>&2 echo "$@"
19+
}
20+
21+
_usage="Usage: $0 [--docker-user <dockerUser>] [--docker-password <dockerPassword>]
22+
Run Docker login script.
23+
--docker-user Username for Docker account.
24+
--docker-password Password for Docker account."
25+
26+
function print_usage {
27+
echoerr "$_usage"
28+
}
29+
30+
while [[ $# -gt 0 ]]
31+
do
32+
key="$1"
33+
34+
case $key in
35+
--docker-user)
36+
DOCKER_USERNAME="$2"
37+
shift 2
38+
;;
39+
--docker-password)
40+
DOCKER_PASSWORD="$2"
41+
shift 2
42+
;;
43+
-h|--help)
44+
print_usage
45+
exit 0
46+
;;
47+
*) # unknown option
48+
echoerr "Unknown option $1"
49+
exit 1
50+
;;
51+
esac
52+
done
53+
54+
function docker_login() {
55+
for i in `seq 5`; do
56+
output=$(echo $2 | docker login --username=$1 --password-stdin 2>&1)
57+
# Check if the exit code is 0
58+
if [[ $? -eq 0 ]]; then
59+
echo "Docker login successful."
60+
return 0
61+
else
62+
echo "Docker login failed, retrying in 5s"
63+
echo "Error output: $output"
64+
sleep 5
65+
fi
66+
done
67+
68+
# Exit with a non-zero code if it never succeeds
69+
echo "Docker login failed after multiple attempts."
70+
return 1
71+
}
72+
73+
# Never trace, to avoid logging password.
74+
# Dont exit on error, docker_login handles errors directly.
75+
set +ex
76+
77+
# Exit if credentials are not set
78+
if [[ -z "$DOCKER_USERNAME" || -z "$DOCKER_PASSWORD" ]]; then
79+
echoerr "Docker username or password not provided."
80+
exit 1
81+
fi
82+
83+
docker_login "${DOCKER_USERNAME}" "${DOCKER_PASSWORD}"

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+
[ "$DOCKER_REGISTRY" != "docker.io" ] || ./ci/jenkins/docker_login.sh --docker-user ${{DOCKER_USERNAME}} --docker-password ${{DOCKER_PASSWORD}}
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+
[ "$DOCKER_REGISTRY" != "docker.io" ] || ./ci/jenkins/docker_login.sh --docker-user ${{DOCKER_USERNAME}} --docker-password ${{DOCKER_PASSWORD}}
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+
[ "$DOCKER_REGISTRY" != "docker.io" ] || ./ci/jenkins/docker_login.sh --docker-user ${{DOCKER_USERNAME}} --docker-password ${{DOCKER_PASSWORD}}
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+
[ "$DOCKER_REGISTRY" != "docker.io" ] || ./ci/jenkins/docker_login.sh --docker-user ${{DOCKER_USERNAME}} --docker-password ${{DOCKER_PASSWORD}}
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+
[ "$DOCKER_REGISTRY" != "docker.io" ] || ./ci/jenkins/docker_login.sh --docker-user ${{DOCKER_USERNAME}} --docker-password ${{DOCKER_PASSWORD}}
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+
[ "$DOCKER_REGISTRY" != "docker.io" ] || ./ci/jenkins/docker_login.sh --docker-user ${{DOCKER_USERNAME}} --docker-password ${{DOCKER_PASSWORD}}
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+
[ "$DOCKER_REGISTRY" != "docker.io" ] || ./ci/jenkins/docker_login.sh --docker-user ${{DOCKER_USERNAME}} --docker-password ${{DOCKER_PASSWORD}}
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+
[ "$DOCKER_REGISTRY" != "docker.io" ] || ./ci/jenkins/docker_login.sh --docker-user ${{DOCKER_USERNAME}} --docker-password ${{DOCKER_PASSWORD}}
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+
[ "$DOCKER_REGISTRY" != "docker.io" ] || ./ci/jenkins/docker_login.sh --docker-user ${{DOCKER_USERNAME}} --docker-password ${{DOCKER_PASSWORD}}
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+
[ "$DOCKER_REGISTRY" != "docker.io" ] || ./ci/jenkins/docker_login.sh --docker-user ${{DOCKER_USERNAME}} --docker-password ${{DOCKER_PASSWORD}}
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)