Skip to content

Commit cbad3f4

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 cbad3f4

File tree

5 files changed

+116
-2
lines changed

5 files changed

+116
-2
lines changed

ci/jenkins/docker_login.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
_usage="Usage: $0 [--docker-user <dockerUser>] [--docker-password <dockerPassword>]
2+
Run Docker login script.
3+
--docker-user Username for Docker account.
4+
--docker-password Password for Docker account."
5+
6+
while [[ $# -gt 0 ]]
7+
do
8+
key="$1"
9+
10+
case $key in
11+
--docker-user)
12+
dockerUser="$2"
13+
shift 2
14+
;;
15+
--docker-password)
16+
dockerPassword="$2"
17+
shift 2
18+
;;
19+
-h|--help)
20+
print_usage
21+
exit 0
22+
;;
23+
*) # unknown option
24+
echoerr "Unknown option $1"
25+
exit 1
26+
;;
27+
esac
28+
done
29+
30+
function docker_login() {
31+
set +ex
32+
for i in `seq 5`; do
33+
# Use --password-stdin to avoid a warning message
34+
echo $2 docker login --username=$1 --password-stdin
35+
if [[ "$?" -ne 0 ]]; then
36+
sleep 5s
37+
echo "Docker login failed. Retrying"
38+
continue
39+
fi
40+
break
41+
done
42+
set -ex
43+
}
44+
45+
docker_login "${dockerUser}" "${dockerPassword}"

ci/jenkins/jobs/macros.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
- shell: |-
103103
#!/bin/bash
104104
set -ex
105+
./ci/jenkins/docker_login.sh --docker-user "${{DOCKER_USERNAME}}" --docker-password "${{DOCKER_PASSWORD}}"
105106
DOCKER_REGISTRY="$(head -n1 ci/docker-registry)"
106107
./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
@@ -111,6 +112,7 @@
111112
- shell: |-
112113
#!/bin/bash
113114
set -ex
115+
./ci/jenkins/docker_login.sh --docker-user "${{DOCKER_USERNAME}}" --docker-password "${{DOCKER_PASSWORD}}"
114116
DOCKER_REGISTRY="$(head -n1 ci/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
@@ -127,6 +129,7 @@
127129
- shell: |-
128130
#!/bin/bash
129131
set -ex
132+
./ci/jenkins/docker_login.sh --docker-user "${{DOCKER_USERNAME}}" --docker-password "${{DOCKER_PASSWORD}}"
130133
DOCKER_REGISTRY="$(head -n1 ci/docker-registry)"
131134
./ci/jenkins/test.sh --testcase '{e2e_type}' --registry ${{DOCKER_REGISTRY}}
132135
@@ -136,6 +139,7 @@
136139
- shell: |-
137140
#!/bin/bash
138141
set -ex
142+
./ci/jenkins/docker_login.sh --docker-user "${{DOCKER_USERNAME}}" --docker-password "${{DOCKER_PASSWORD}}"
139143
DOCKER_REGISTRY="$(head -n1 ci/docker-registry)"
140144
./ci/jenkins/test.sh --testcase '{conformance_type}' --registry ${{DOCKER_REGISTRY}}
141145
@@ -145,6 +149,7 @@
145149
- shell: |-
146150
#!/bin/bash
147151
set -e
152+
./ci/jenkins/docker_login.sh --docker-user "${{DOCKER_USERNAME}}" --docker-password "${{DOCKER_PASSWORD}}"
148153
DOCKER_REGISTRY="$(head -n1 ci/docker-registry)"
149154
./ci/jenkins/test.sh --testcase e2e --registry ${DOCKER_REGISTRY} --workdir "/home/ubuntu" --kubeconfig "/home/ubuntu/kube.conf" --testbed-type "flexible-ipam"
150155
@@ -207,6 +212,7 @@
207212
- shell: |-
208213
#!/bin/bash
209214
set -ex
215+
./ci/jenkins/docker_login.sh --docker-user "${{DOCKER_USERNAME}}" --docker-password "${{DOCKER_PASSWORD}}"
210216
DOCKER_REGISTRY="$(head -n1 ci/docker-registry)"
211217
KIND_TIMEOUT=135
212218
FULL_CLUSTER_NAME='{kind_cluster_name}'-"${{BUILD_NUMBER}}"
@@ -230,6 +236,7 @@
230236
- shell: |-
231237
#!/bin/bash
232238
set -ex
239+
./ci/jenkins/docker_login.sh --docker-user "${{DOCKER_USERNAME}}" --docker-password "${{DOCKER_PASSWORD}}"
233240
DOCKER_REGISTRY="$(head -n1 ci/docker-registry)"
234241
KIND_TIMEOUT=135
235242
FULL_CLUSTER_NAME='{kind_cluster_name}'-"${{BUILD_NUMBER}}"
@@ -272,6 +279,7 @@
272279
- shell: |-
273280
#!/bin/bash
274281
set -e
282+
./ci/jenkins/docker_login.sh --docker-user "${{DOCKER_USERNAME}}" --docker-password "${{DOCKER_PASSWORD}}"
275283
DOCKER_REGISTRY="$(head -n1 ci/docker-registry)"
276284
./ci/jenkins/test-mc.sh --testcase e2e --registry ${DOCKER_REGISTRY} --mc-gateway --codecov-token "${CODECOV_TOKEN}" --coverage --kind
277285
@@ -281,6 +289,7 @@
281289
- shell: |-
282290
#!/bin/bash
283291
set -e
292+
./ci/jenkins/docker_login.sh --docker-user "${{DOCKER_USERNAME}}" --docker-password "${{DOCKER_PASSWORD}}"
284293
DOCKER_REGISTRY="$(head -n1 ci/docker-registry)"
285294
./ci/jenkins/test.sh --testcase e2e --registry ${DOCKER_REGISTRY} --testbed-type jumper
286295
@@ -290,6 +299,7 @@
290299
- shell: |-
291300
#!/bin/bash
292301
set -e
302+
./ci/jenkins/docker_login.sh --docker-user "${{DOCKER_USERNAME}}" --docker-password "${{DOCKER_PASSWORD}}"
293303
DOCKER_REGISTRY="$(head -n1 ci/docker-registry)"
294304
./ci/jenkins/test.sh --testcase '{conformance_type}' --registry ${{DOCKER_REGISTRY}} --testbed-type jumper
295305

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)