From 4a1eca103c3a40e98f36328ca03f2eef02de05d9 Mon Sep 17 00:00:00 2001 From: LongyuZhang Date: Thu, 9 Nov 2023 10:45:13 -0500 Subject: [PATCH] Support base docker registry login to increase pull limit (#4842) - Pulling image from dockerhub reaches limit during release - Enabling base_docker_registry_credential to increase this limit Signed-off-by: LongyuZhang --- buildenv/jenkins/JenkinsfileBase | 14 ++++- buildenv/jenkins/testJobTemplate | 2 + external/common_functions.sh | 5 ++ external/criu-portable-checkpoint/build.xml | 24 ++++++++- .../criu-ubi-portable-checkpoint/build.xml | 24 ++++++++- external/external.sh | 53 ++++++++++++++----- 6 files changed, 106 insertions(+), 16 deletions(-) diff --git a/buildenv/jenkins/JenkinsfileBase b/buildenv/jenkins/JenkinsfileBase index b0ca1e0dc3..26dcbaa2a8 100644 --- a/buildenv/jenkins/JenkinsfileBase +++ b/buildenv/jenkins/JenkinsfileBase @@ -12,8 +12,17 @@ def makeTest(testParam) { } try { sh "$tearDownCmd" - if (env.DOCKER_REGISTRY_URL && env.DOCKER_REGISTRY_URL_CREDENTIAL_ID) { - withCredentials([usernamePassword(credentialsId: "${env.DOCKER_REGISTRY_URL_CREDENTIAL_ID}", usernameVariable: 'DOCKER_REGISTRY_CREDENTIALS_USR', passwordVariable: 'DOCKER_REGISTRY_CREDENTIALS_PSW')]) { + if (env.DOCKER_REGISTRY_URL && env.DOCKER_REGISTRY_URL_CREDENTIAL_ID && env.BASE_DOCKER_REGISTRY_CREDENTIAL_ID) { + withCredentials([ + usernamePassword(credentialsId: "${env.DOCKER_REGISTRY_URL_CREDENTIAL_ID}", usernameVariable: 'DOCKER_REGISTRY_CREDENTIALS_USR', passwordVariable: 'DOCKER_REGISTRY_CREDENTIALS_PSW'), + usernamePassword(credentialsId: "${env.BASE_DOCKER_REGISTRY_CREDENTIAL_ID}", usernameVariable: 'BASE_DOCKER_REGISTRY_CREDENTIAL_USR', passwordVariable: 'BASE_DOCKER_REGISTRY_CREDENTIAL_PSW') + ]) { + sh "$makeTestCmd" + } + } else if (env.DOCKER_REGISTRY_URL && env.DOCKER_REGISTRY_URL_CREDENTIAL_ID) { + withCredentials([ + usernamePassword(credentialsId: "${env.DOCKER_REGISTRY_URL_CREDENTIAL_ID}", usernameVariable: 'DOCKER_REGISTRY_CREDENTIALS_USR', passwordVariable: 'DOCKER_REGISTRY_CREDENTIALS_PSW'), + ]) { sh "$makeTestCmd" } } else { @@ -89,6 +98,7 @@ def setupEnv() { env.DOCKER_REGISTRY_URL = params.DOCKER_REGISTRY_URL ? params.DOCKER_REGISTRY_URL : "" env.DOCKER_REGISTRY_DIR = params.DOCKER_REGISTRY_DIR ? params.DOCKER_REGISTRY_DIR : "" env.DOCKER_REGISTRY_URL_CREDENTIAL_ID = params.DOCKER_REGISTRY_URL_CREDENTIAL_ID ? params.DOCKER_REGISTRY_URL_CREDENTIAL_ID : "" + env.BASE_DOCKER_REGISTRY_CREDENTIAL_ID = params.BASE_DOCKER_REGISTRY_CREDENTIAL_ID ? params.BASE_DOCKER_REGISTRY_CREDENTIAL_ID : "" ITERATIONS = params.ITERATIONS ? "${params.ITERATIONS}".toInteger() : 1 env.TKG_ITERATIONS = params.TKG_ITERATIONS ? "${params.TKG_ITERATIONS}".toInteger() : 1 env.EXIT_FAILURE = params.EXIT_FAILURE ? params.EXIT_FAILURE : false diff --git a/buildenv/jenkins/testJobTemplate b/buildenv/jenkins/testJobTemplate index 783e406c3f..85dbcf025d 100644 --- a/buildenv/jenkins/testJobTemplate +++ b/buildenv/jenkins/testJobTemplate @@ -49,6 +49,7 @@ if (!binding.hasVariable('CUSTOMIZED_SDK_URL_CREDENTIAL_ID')) CUSTOMIZED_SDK_URL if (!binding.hasVariable('DOCKER_REGISTRY_URL')) DOCKER_REGISTRY_URL = "" if (!binding.hasVariable('DOCKER_REGISTRY_DIR')) DOCKER_REGISTRY_DIR = "" if (!binding.hasVariable('DOCKER_REGISTRY_URL_CREDENTIAL_ID')) DOCKER_REGISTRY_URL_CREDENTIAL_ID = "" +if (!binding.hasVariable('BASE_DOCKER_REGISTRY_CREDENTIAL_ID')) BASE_DOCKER_REGISTRY_CREDENTIAL_ID = "" if (!binding.hasVariable('SLACK_CHANNEL')) SLACK_CHANNEL = "" if (!binding.hasVariable('TRIGGER_SCHEDULE')) TRIGGER_SCHEDULE = "" if (!binding.hasVariable('LIGHT_WEIGHT_CHECKOUT')) LIGHT_WEIGHT_CHECKOUT = true @@ -325,6 +326,7 @@ ARCH_OS_LIST.each { ARCH_OS -> stringParam('DOCKER_REGISTRY_URL', DOCKER_REGISTRY_URL, "Only use this if you need to access a docker registry") stringParam('DOCKER_REGISTRY_DIR', DOCKER_REGISTRY_DIR, "Only use this if you need to specify the directory in docker registry") stringParam('DOCKER_REGISTRY_URL_CREDENTIAL_ID', DOCKER_REGISTRY_URL_CREDENTIAL_ID, "Only use this if the docker registry you access needs credential") + stringParam('BASE_DOCKER_REGISTRY_CREDENTIAL_ID', BASE_DOCKER_REGISTRY_CREDENTIAL_ID, "Only use this if base docker registry credential is needed to avoid reach limit") stringParam('UPSTREAM_JOB_NAME', "", '''Upstream job name from the same Jenkins server to download JDK. e.g., UploadFile
Only set when SDK_RESOURCE=upstream. It has to be used together with UPSTREAM_JOB_NUMBER
''') stringParam('UPSTREAM_JOB_NUMBER', "", '''Upstream job number from the same Jenkins server to download JDK. e.g., 40
diff --git a/external/common_functions.sh b/external/common_functions.sh index 774f9b4cef..c8eb12ba85 100755 --- a/external/common_functions.sh +++ b/external/common_functions.sh @@ -177,6 +177,11 @@ function set_platform() { platform=$1 } +# Set base_docker_registry_url +function set_base_docker_registry_url() { + base_docker_registry_url="$1" +} + # Set base_docker_registry_dir function set_base_docker_registry_dir() { base_docker_registry_dir="$1" diff --git a/external/criu-portable-checkpoint/build.xml b/external/criu-portable-checkpoint/build.xml index cb57908f64..b9a3847a73 100644 --- a/external/criu-portable-checkpoint/build.xml +++ b/external/criu-portable-checkpoint/build.xml @@ -15,7 +15,29 @@ - + + + + + + + + + + + + + + + + + + + + + + + diff --git a/external/criu-ubi-portable-checkpoint/build.xml b/external/criu-ubi-portable-checkpoint/build.xml index 792934e39c..8cf54eb9a3 100644 --- a/external/criu-ubi-portable-checkpoint/build.xml +++ b/external/criu-ubi-portable-checkpoint/build.xml @@ -15,7 +15,29 @@ - + + + + + + + + + + + + + + + + + + + + + + + diff --git a/external/external.sh b/external/external.sh index 1c3587006c..23a96aa439 100755 --- a/external/external.sh +++ b/external/external.sh @@ -13,7 +13,7 @@ # limitations under the License. # -# script runs in 4 modes - build / run / load / clean +# script runs in 5 modes - prepare / build / run / load / clean set -e tag=nightly @@ -47,7 +47,8 @@ container_rmi="docker rmi" docker_registry_required="false" docker_registry_url="" docker_registry_dir="" -base_docker_registry_dir="public" +base_docker_registry_url="default" +base_docker_registry_dir="default" reportdst="false" reportsrc="false" docker_args="" @@ -57,7 +58,7 @@ imageArg="" usage () { - echo 'Usage : external.sh --dir TESTDIR --tag DOCKERIMAGE_TAG --version JDK_VERSION --impl JDK_IMPL [--docker_os docker_os][--platform PLATFORM] [--portable portable] [--node_name node_name] [--node_labels node_labels] [--docker_registry_required docker_registry_required] [--docker_registry_url DOCKER_REGISTRY_URL] [--docker_registry_dir DOCKER_REGISTRY_DIR] [--base_docker_registry_dir baseDockerRegistryDir] [--mount_jdk mount_jdk] [--test_root TEST_ROOT] [--reportsrc appReportDir] [--reportdst REPORTDIR] [--testtarget target] [--docker_args EXTRA_DOCKER_ARGS] [--build|--run|--load|--clean]' + echo 'Usage : external.sh --dir TESTDIR --tag DOCKERIMAGE_TAG --version JDK_VERSION --impl JDK_IMPL [--docker_os docker_os][--platform PLATFORM] [--portable portable] [--node_name node_name] [--node_labels node_labels] [--docker_registry_required docker_registry_required] [--docker_registry_url DOCKER_REGISTRY_URL] [--docker_registry_dir DOCKER_REGISTRY_DIR] [--base_docker_registry_url baseDockerRegistryUrl] [--base_docker_registry_dir baseDockerRegistryDir] [--mount_jdk mount_jdk] [--test_root TEST_ROOT] [--reportsrc appReportDir] [--reportdst REPORTDIR] [--testtarget target] [--docker_args EXTRA_DOCKER_ARGS] [--build|--run|--load|--clean]' } supported_tests="external_custom aot camel criu-portable-checkpoint criu-portable-restore criu-ubi-portable-checkpoint criu-ubi-portable-restore derby elasticsearch jacoco jenkins functional-test kafka lucene-solr openliberty-mp-tck payara-mp-tck quarkus quarkus_quickstarts scala system-test tomcat tomee wildfly wycheproof netty spring" @@ -175,9 +176,17 @@ parseCommandLineArgs() { docker_image_source_job_name=${dir_array[0]} build_number=${dir_array[1]};; + "--base_docker_registry_url" ) + if [ -z "$1" ]; then + base_docker_registry_url="default"; + else + base_docker_registry_url="$1"; + fi + shift;; + "--base_docker_registry_dir" ) if [ -z "$1" ]; then - base_docker_registry_dir="public"; + base_docker_registry_dir="default"; else base_docker_registry_dir="$1"; fi @@ -198,6 +207,9 @@ parseCommandLineArgs() { "--testtarget" ) testtarget="$1"; shift;; + "--prepare" | "-p" ) + command_type=prepare;; + "--build" | "-b" ) command_type=build;; @@ -270,17 +282,34 @@ parseCommandLineArgs "$@" # set DOCKER_HOST env variables # DOCKER_HOST=$(docker-ip $test-test) -if [ $command_type == "build" ]; then - # Temporarily ubi image with criu binary is only available internally - if [[ $base_docker_registry_dir != "public" ]]; then - echo "Private Docker Registry login starts to obtain base Docker Image:" - echo $DOCKER_REGISTRY_CREDENTIALS_PSW | $container_login --username=$DOCKER_REGISTRY_CREDENTIALS_USR --password-stdin $docker_registry_url +if [ $command_type == "prepare" ]; then + # Specify docker.io or internal registry to prepare base image with login to increase pull limit or authenticate; Redhat Registry no login. + if [[ $base_docker_registry_url != "default" ]]; then + echo "Base Docker Registry login starts to obtain Base Docker Image:" + # Temporarily criu-ubi image with criu binary is only available internally + if [[ "${test}" != *"criu-ubi"* ]]; then + echo $BASE_DOCKER_REGISTRY_CREDENTIAL_PSW | $container_login --username=$BASE_DOCKER_REGISTRY_CREDENTIAL_USR --password-stdin $base_docker_registry_url + else + echo $DOCKER_REGISTRY_CREDENTIALS_PSW | $container_login --username=$DOCKER_REGISTRY_CREDENTIALS_USR --password-stdin $base_docker_registry_url + fi - echo "$container_pull $docker_registry_url/$base_docker_registry_dir:latest" - $container_pull $docker_registry_url/$base_docker_registry_dir:latest + if [[ $base_docker_registry_dir == "default" ]]; then + base_docker_image_name="eclipse-temurin:${JDK_VERSION}-jdk" + if [[ "${JDK_IMPL}" == *"openj9"* ]]; then + base_docker_image_name="ibm-semeru-runtimes:open-${JDK_VERSION}-jdk" + fi + else + base_docker_image_name="$base_docker_registry_dir:latest" + fi + + echo "$container_pull $base_docker_registry_url/$base_docker_image_name" + $container_pull $base_docker_registry_url/$base_docker_image_name - $container_logout $docker_registry_url + $container_logout $base_docker_registry_url fi +fi + +if [ $command_type == "build" ]; then echo "build_image.sh $test $version $impl $docker_os $package $build_type $platform $base_docker_registry_dir $check_external_custom $imageArg" source $(dirname "$0")/build_image.sh $test $version $impl $docker_os $package $build_type $platform "$base_docker_registry_dir" $check_external_custom $imageArg fi