Skip to content

Commit

Permalink
Support base docker registry login to increase pull limit (#4842)
Browse files Browse the repository at this point in the history
- Pulling image from dockerhub reaches limit during release
- Enabling base_docker_registry_credential to increase this limit

Signed-off-by: LongyuZhang <[email protected]>
  • Loading branch information
LongyuZhang authored Nov 9, 2023
1 parent 8270e9c commit 4a1eca1
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 16 deletions.
14 changes: 12 additions & 2 deletions buildenv/jenkins/JenkinsfileBase
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions buildenv/jenkins/testJobTemplate
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<br/>
Only set when SDK_RESOURCE=upstream. It has to be used together with UPSTREAM_JOB_NUMBER <br/>''')
stringParam('UPSTREAM_JOB_NUMBER', "", '''Upstream job number from the same Jenkins server to download JDK. e.g., 40<br/>
Expand Down
5 changes: 5 additions & 0 deletions external/common_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
24 changes: 23 additions & 1 deletion external/criu-portable-checkpoint/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,29 @@
<mkdir dir="${DEST}"/>
</target>

<target name="dist" depends="move_scripts,clean_image,build_image" description="generate the distribution">
<target name="prepare_base_image" depends="move_scripts,clean_image" description="prepare the base image">
<echo message="Executing external.sh --prepare --dir ${TEST} --tag ${dockerImageTag} --version ${JDK_VERSION} --impl ${JDK_IMPL} --base_docker_registry_url 'docker.io' --base_docker_registry_dir 'default' --docker_args ${extra_docker_args} " />
<exec executable="bash" failonerror="true">
<arg value="${DEST_EXTERNAL}/external.sh"/>
<arg value="--prepare"/>
<arg value="--dir"/>
<arg value="${TEST}"/>
<arg value="--tag"/>
<arg value="${dockerImageTag}"/>
<arg value="--version"/>
<arg value="${JDK_VERSION}"/>
<arg value="--impl"/>
<arg value="${JDK_IMPL}"/>
<arg value="--base_docker_registry_url"/>
<arg value="docker.io"/>
<arg value="--base_docker_registry_dir"/>
<arg value="default"/>
<arg value="--docker_args"/>
<arg value="${extra_docker_args}"/>
</exec>
</target>

<target name="dist" depends="prepare_base_image,build_image" description="generate the distribution">
<copy todir="${DEST}">
<fileset dir="${src}" includes="*.xml, *.mk"/>
</copy>
Expand Down
24 changes: 23 additions & 1 deletion external/criu-ubi-portable-checkpoint/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,29 @@
<mkdir dir="${DEST}"/>
</target>

<target name="build_image" depends="move_scripts,clean_image" description="build the image">
<target name="prepare_base_image" depends="move_scripts,clean_image" description="prepare the base image">
<echo message="Executing external.sh --prepare --dir ${TEST} --tag ${dockerImageTag} --version ${JDK_VERSION} --impl ${JDK_IMPL} --base_docker_registry_url '${env.DOCKER_REGISTRY_URL}' --base_docker_registry_dir 'ubi8-with-criu/${env.SPEC}-ubi8-criu' --docker_args ${extra_docker_args} " />
<exec executable="bash" failonerror="true">
<arg value="${DEST_EXTERNAL}/external.sh"/>
<arg value="--prepare"/>
<arg value="--dir"/>
<arg value="${TEST}"/>
<arg value="--tag"/>
<arg value="${dockerImageTag}"/>
<arg value="--version"/>
<arg value="${JDK_VERSION}"/>
<arg value="--impl"/>
<arg value="${JDK_IMPL}"/>
<arg value="--base_docker_registry_url"/>
<arg value="${env.DOCKER_REGISTRY_URL}"/>
<arg value="--base_docker_registry_dir"/>
<arg value="ubi8-with-criu/${env.SPEC}-ubi8-criu"/>
<arg value="--docker_args"/>
<arg value="${extra_docker_args}"/>
</exec>
</target>

<target name="build_image" depends="prepare_base_image" description="build the image">
<echo message="Executing external.sh --build --dir ${TEST} --tag ${dockerImageTag} --version ${JDK_VERSION} --impl ${JDK_IMPL} --base_docker_registry_dir 'ubi8-with-criu/${env.SPEC}-ubi8-criu' --docker_registry_url ${env.DOCKER_REGISTRY_URL} --docker_args ${extra_docker_args} " />
<exec executable="bash" failonerror="true">
<arg value="${DEST_EXTERNAL}/external.sh"/>
Expand Down
53 changes: 41 additions & 12 deletions external/external.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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=""
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -198,6 +207,9 @@ parseCommandLineArgs() {
"--testtarget" )
testtarget="$1"; shift;;

"--prepare" | "-p" )
command_type=prepare;;

"--build" | "-b" )
command_type=build;;

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4a1eca1

Please sign in to comment.