Skip to content

Commit

Permalink
Add Docker login to Jenkins script to avoid rate limit issue (antrea-…
Browse files Browse the repository at this point in the history
…io#6368) (antrea-io#6440)

* 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

* Fix some issues in docker_login.sh

Signed-off-by: Shuyang Xin <gavinx@vmware.com>
Signed-off-by: Antonin Bas <antonin.bas@broadcom.com>
  • Loading branch information
luolanzone authored Jun 13, 2024
1 parent 99b732b commit 312b5a7
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 24 deletions.
83 changes: 83 additions & 0 deletions ci/jenkins/docker_login.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env bash

# Copyright 2024 Antrea Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

function echoerr {
>&2 echo "$@"
}

_usage="Usage: $0 [--docker-user <dockerUser>] [--docker-password <dockerPassword>]
Run Docker login script.
--docker-user Username for Docker account.
--docker-password Password for Docker account."

function print_usage {
echoerr "$_usage"
}

while [[ $# -gt 0 ]]
do
key="$1"

case $key in
--docker-user)
DOCKER_USERNAME="$2"
shift 2
;;
--docker-password)
DOCKER_PASSWORD="$2"
shift 2
;;
-h|--help)
print_usage
exit 0
;;
*) # unknown option
echoerr "Unknown option $1"
exit 1
;;
esac
done

function docker_login() {
for i in `seq 5`; do
output=$(echo $2 | docker login --username=$1 --password-stdin 2>&1)
# Check if the exit code is 0
if [[ $? -eq 0 ]]; then
echo "Docker login successful."
return 0
else
echo "Docker login failed, retrying in 5s"
echo "Error output: $output"
sleep 5
fi
done

# Exit with a non-zero code if it never succeeds
echo "Docker login failed after multiple attempts."
return 1
}

# Never trace, to avoid logging password.
# Dont exit on error, docker_login handles errors directly.
set +ex

# Exit if credentials are not set
if [[ -z "$DOCKER_USERNAME" || -z "$DOCKER_PASSWORD" ]]; then
echoerr "Docker username or password not provided."
exit 1
fi

docker_login "${DOCKER_USERNAME}" "${DOCKER_PASSWORD}"
45 changes: 23 additions & 22 deletions ci/jenkins/jobs/macros.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@
#!/bin/bash
set -ex
DOCKER_REGISTRY="$(head -n1 ci/docker-registry)"
./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}"
[ "$DOCKER_REGISTRY" != "docker.io" ] || ./ci/jenkins/docker_login.sh --docker-user ${{DOCKER_USERNAME}} --docker-password ${{DOCKER_PASSWORD}}
./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}}"
- builder:
name: builder-conformance
Expand All @@ -112,6 +113,7 @@
#!/bin/bash
set -ex
DOCKER_REGISTRY="$(head -n1 ci/docker-registry)"
[ "$DOCKER_REGISTRY" != "docker.io" ] || ./ci/jenkins/docker_login.sh --docker-user ${{DOCKER_USERNAME}} --docker-password ${{DOCKER_PASSWORD}}
./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}}"
- builder:
Expand All @@ -122,31 +124,24 @@
./ci/jenkins/test.sh --testcase windows-install-ovs
- builder:
name: builder-e2e-proxyall-win
name: builder-e2e-win
builders:
- shell: |-
#!/bin/bash
set -ex
DOCKER_REGISTRY="$(head -n1 ci/docker-registry)"
./ci/jenkins/test.sh --testcase windows-e2e --registry ${DOCKER_REGISTRY} --proxyall
[ "$DOCKER_REGISTRY" != "docker.io" ] || ./ci/jenkins/docker_login.sh --docker-user ${{DOCKER_USERNAME}} --docker-password ${{DOCKER_PASSWORD}}
./ci/jenkins/test.sh --testcase '{e2e_type}' --registry ${{DOCKER_REGISTRY}}
- builder:
name: builder-e2e-win
builders:
- shell: |-
#!/bin/bash
set -ex
DOCKER_REGISTRY="$(head -n1 ci/docker-registry)"
./ci/jenkins/test.sh --testcase windows-containerd-e2e --registry ${{DOCKER_REGISTRY}} --win-image-node '{win_image_node}'
- builder:
name: builder-conformance-win
builders:
- shell: |-
#!/bin/bash
set -ex
DOCKER_REGISTRY="$(head -n1 ci/docker-registry)"
./ci/jenkins/test.sh --testcase '{conformance_type}' --registry ${{DOCKER_REGISTRY}} --win-image-node '{win_image_node}'
name: builder-conformance-win
builders:
- shell: |-
#!/bin/bash
set -ex
DOCKER_REGISTRY="$(head -n1 ci/docker-registry)"
[ "$DOCKER_REGISTRY" != "docker.io" ] || ./ci/jenkins/docker_login.sh --docker-user ${{DOCKER_USERNAME}} --docker-password ${{DOCKER_PASSWORD}}
./ci/jenkins/test.sh --testcase '{conformance_type}' --registry ${{DOCKER_REGISTRY}}
- builder:
name: builder-flexible-ipam-e2e
Expand All @@ -155,7 +150,8 @@
#!/bin/bash
set -e
DOCKER_REGISTRY="$(head -n1 ci/docker-registry)"
./ci/jenkins/test.sh --testcase e2e --registry ${DOCKER_REGISTRY} --workdir "/home/ubuntu" --kubeconfig "/home/ubuntu/kube.conf" --testbed-type "flexible-ipam"
[ "$DOCKER_REGISTRY" != "docker.io" ] || ./ci/jenkins/docker_login.sh --docker-user ${{DOCKER_USERNAME}} --docker-password ${{DOCKER_PASSWORD}}
./ci/jenkins/test.sh --testcase e2e --registry ${{DOCKER_REGISTRY}} --workdir "/home/ubuntu" --kubeconfig "/home/ubuntu/kube.conf" --testbed-type "flexible-ipam"
- builder:
name: builder-flow-visibility
Expand Down Expand Up @@ -217,6 +213,7 @@
#!/bin/bash
set -ex
DOCKER_REGISTRY="$(head -n1 ci/docker-registry)"
[ "$DOCKER_REGISTRY" != "docker.io" ] || ./ci/jenkins/docker_login.sh --docker-user ${{DOCKER_USERNAME}} --docker-password ${{DOCKER_PASSWORD}}
KIND_TIMEOUT=135
FULL_CLUSTER_NAME='{kind_cluster_name}'-"${{BUILD_NUMBER}}"
# Delete all Kind clusters created more than 135 mins ago. 135 minutes is the timeout
Expand All @@ -240,6 +237,7 @@
#!/bin/bash
set -ex
DOCKER_REGISTRY="$(head -n1 ci/docker-registry)"
[ "$DOCKER_REGISTRY" != "docker.io" ] || ./ci/jenkins/docker_login.sh --docker-user ${{DOCKER_USERNAME}} --docker-password ${{DOCKER_PASSWORD}}
KIND_TIMEOUT=135
FULL_CLUSTER_NAME='{kind_cluster_name}'-"${{BUILD_NUMBER}}"
# Delete all Kind clusters created more than 135 mins ago. 135 minutes is the timeout
Expand Down Expand Up @@ -282,7 +280,8 @@
#!/bin/bash
set -e
DOCKER_REGISTRY="$(head -n1 ci/docker-registry)"
./ci/jenkins/test-mc.sh --testcase e2e --registry ${DOCKER_REGISTRY} --mc-gateway --codecov-token "${CODECOV_TOKEN}" --coverage --kind
[ "$DOCKER_REGISTRY" != "docker.io" ] || ./ci/jenkins/docker_login.sh --docker-user ${{DOCKER_USERNAME}} --docker-password ${{DOCKER_PASSWORD}}
./ci/jenkins/test-mc.sh --testcase e2e --registry ${{DOCKER_REGISTRY}} --mc-gateway --codecov-token "${CODECOV_TOKEN}" --coverage --kind
- builder:
name: builder-e2e-jumper
Expand All @@ -291,7 +290,8 @@
#!/bin/bash
set -e
DOCKER_REGISTRY="$(head -n1 ci/docker-registry)"
./ci/jenkins/test.sh --testcase e2e --registry ${DOCKER_REGISTRY} --testbed-type jumper
[ "$DOCKER_REGISTRY" != "docker.io" ] || ./ci/jenkins/docker_login.sh --docker-user ${{DOCKER_USERNAME}} --docker-password ${{DOCKER_PASSWORD}}
./ci/jenkins/test.sh --testcase e2e --registry ${{DOCKER_REGISTRY}} --testbed-type jumper
- builder:
name: builder-conformance-jumper
Expand All @@ -300,6 +300,7 @@
#!/bin/bash
set -e
DOCKER_REGISTRY="$(head -n1 ci/docker-registry)"
[ "$DOCKER_REGISTRY" != "docker.io" ] || ./ci/jenkins/docker_login.sh --docker-user ${{DOCKER_USERNAME}} --docker-password ${{DOCKER_PASSWORD}}
./ci/jenkins/test.sh --testcase '{conformance_type}' --registry ${{DOCKER_REGISTRY}} --testbed-type jumper
- builder:
Expand Down
36 changes: 36 additions & 0 deletions ci/jenkins/jobs/projects-cloud.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@
- text:
credential-id: CAPVC_PASSWORD
variable: CAPVC_PASSWORD
- text:
credential-id: DOCKER_USERNAME
variable: DOCKER_USERNAME
- text:
credential-id: DOCKER_PASSWORD
variable: DOCKER_PASSWORD
publishers:
- archive:
allow-empty: true
Expand Down Expand Up @@ -211,6 +217,12 @@
- text:
credential-id: CAPVC_PASSWORD
variable: CAPVC_PASSWORD
- text:
credential-id: DOCKER_USERNAME
variable: DOCKER_USERNAME
- text:
credential-id: DOCKER_PASSWORD
variable: DOCKER_PASSWORD
publishers:
- archive:
allow-empty: true
Expand Down Expand Up @@ -310,6 +322,12 @@
- text:
credential-id: CAPVC_PASSWORD
variable: CAPVC_PASSWORD
- text:
credential-id: DOCKER_USERNAME
variable: DOCKER_USERNAME
- text:
credential-id: DOCKER_PASSWORD
variable: DOCKER_PASSWORD
publishers:
- archive:
allow-empty: true
Expand Down Expand Up @@ -397,6 +415,12 @@
- text:
credential-id: CAPVC_PASSWORD
variable: CAPVC_PASSWORD
- text:
credential-id: DOCKER_USERNAME
variable: DOCKER_USERNAME
- text:
credential-id: DOCKER_PASSWORD
variable: DOCKER_PASSWORD
publishers:
- archive:
allow-empty: true
Expand Down Expand Up @@ -509,6 +533,12 @@
- text:
credential-id: CAPVC_PASSWORD
variable: CAPVC_PASSWORD
- text:
credential-id: DOCKER_USERNAME
variable: DOCKER_USERNAME
- text:
credential-id: DOCKER_PASSWORD
variable: DOCKER_PASSWORD
publishers:
- archive:
allow-empty: true
Expand Down Expand Up @@ -580,6 +610,12 @@
- text:
credential-id: RESOURCEPOOLPATH
variable: RESOURCEPOOLPATH
- text:
credential-id: DOCKER_USERNAME
variable: DOCKER_USERNAME
- text:
credential-id: DOCKER_PASSWORD
variable: DOCKER_PASSWORD
- '{name}-{test_name}-for-gc':
test_name: workload-cluster
node: 'antrea-test-node'
Expand Down
18 changes: 18 additions & 0 deletions ci/jenkins/jobs/projects-lab.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,12 @@
- text:
credential-id: GOVC_DATASTORE
variable: GOVC_DATASTORE
- text:
credential-id: DOCKER_USERNAME
variable: DOCKER_USERNAME
- text:
credential-id: DOCKER_PASSWORD
variable: DOCKER_PASSWORD
publishers:
- archive:
allow-empty: true
Expand Down Expand Up @@ -705,6 +711,12 @@
- text:
credential-id: GOVC_DATASTORE
variable: GOVC_DATASTORE
- text:
credential-id: DOCKER_USERNAME
variable: DOCKER_USERNAME
- text:
credential-id: DOCKER_PASSWORD
variable: DOCKER_PASSWORD
publishers:
- archive:
allow-empty: true
Expand Down Expand Up @@ -761,6 +773,12 @@
- text:
credential-id: GOVC_DATASTORE
variable: GOVC_DATASTORE
- text:
credential-id: DOCKER_USERNAME
variable: DOCKER_USERNAME
- text:
credential-id: DOCKER_PASSWORD
variable: DOCKER_PASSWORD
publishers:
- archive:
allow-empty: true
Expand Down
3 changes: 1 addition & 2 deletions ci/jenkins/test-vmc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -638,14 +638,13 @@ function collect_coverage() {
}

function cleanup_cluster() {
release_static_ip
echo "=== Cleaning up VMC cluster ${CLUSTER} ==="
export KUBECONFIG=$KUBECONFIG_PATH

kubectl delete ns ${CLUSTER}
rm -rf "${GIT_CHECKOUT_DIR}/jenkins"
echo "=== Cleanup cluster ${CLUSTER} succeeded ==="

release_static_ip
}

function garbage_collection() {
Expand Down

0 comments on commit 312b5a7

Please sign in to comment.