diff --git a/Jenkinsfile b/Jenkinsfile index 8053203..69da988 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -12,7 +12,7 @@ * EXERCISE_FOLDERS has the image name and corresponding build folder **/ -TARGET_BRANCH = '202310' +TARGET_BRANCH = '202310-multiarch' EXERCISE_FOLDERS = [ "base": "base", @@ -22,11 +22,12 @@ EXERCISE_FOLDERS = [ ] pipeline { - agent any + agent { node { label 'docker-multi-arch' } } environment { maintainer = "t" imagename = 'g' tag = 'l' + DOCKERHUBPW=credentials('tieradmin-dockerhub-pw') } stages { stage('Setting build context') { @@ -70,22 +71,32 @@ pipeline { stage('Build exerciseSets') { steps { script { - docker.withRegistry('https://registry.hub.docker.com/', "dockerhub-${maintainer}") { - // def tagSet = generateTagSet() - // def builds = build(tagSet) if(env.BRANCH_NAME == TARGET_BRANCH) { //builds.each{ k, v -> echo ("push ${k}") } //for local testing // builds.each{ k, v -> v.push(k) } <- not used anymore + // the following command needs to be run first on a new node, but not after that + // sh 'docker buildx create --use --name multiarch --append' EXERCISE_FOLDERS.each { exercise, folder -> - def build = docker.build("${maintainer}/${imagename}:${exercise}-${tag}", "--no-cache --pull --build-arg VERSION_TAG=${tag} ${folder}") - build.push("${exercise}-${tag}") + // old non multi-arch way + // def build = docker.build("${maintainer}/${imagename}:${exercise}-${tag}", "--no-cache --pull --build-arg VERSION_TAG=${tag} ${folder}") + // build.push("${exercise}-${tag}") + + // switch to buildx, which is not supported by the jenkins docker plugin + sh 'docker buildx inspect --bootstrap' + sh 'docker buildx ls' + sh 'docker login -u tieradmin -p $DOCKERHUBPW' + sh 'docker buildx inspect --bootstrap' + sh 'docker buildx ls' + sh "docker buildx build --platform linux/amd64 -t ${imagename} --build-arg VERSION_TAG=${tag} --load ${folder}" + sh "docker buildx build --platform linux/arm64 -t ${imagename}:arm64 --build-arg VERSION_TAG=${tag} --load ${folder}" + echo "Pushing image ${maintainer}/${imagename}:${exercise}-${tag} to dockerhub..." + sh "docker buildx build --push --platform linux/arm64,linux/amd64 -t ${maintainer}/${imagename}:${exercise}-${tag} --build-arg VERSION_TAG=${tag} ${folder}" } } else { echo "not building images, since the SCM branch is not ${TARGET_BRANCH}" } - } } } }