Skip to content
Permalink
202503
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
@credman
Latest commit d888ab5 Feb 15, 2025 History
4 contributors

Users who have contributed to this file

@chubing @credman @wgthom @mchyzer
138 lines (124 sloc) 5.5 KB
/** Builds images for the Grouper Training Env
* Each class has a set of images. Each class's image sets are independent, but within
* a class each image builds upon the prior exercise. Therefore all images are built
* first and then push to the repo. Order of the build is important, but ordering of the
* image pushes are not. If an image is missing the extra layers get pushed, then the
* missing layers only get tagged when they are pushed.
**/
/** Each class is an associated docker image.
* EXERCISE_FOLDERS has the image name and corresponding build folder
**/
TARGET_BRANCH = '202503'
EXERCISE_FOLDERS = [
"base": "base",
"101.1.1": "ex101/ex101.1.1",
//"201.end": "ex201/ex201.end",
//"401.end": "ex401/ex401.end",
]
pipeline {
agent { node { label 'docker-multi-arch' } }
environment {
maintainer = "t"
imagename = 'g'
tag = 'l'
DOCKERHUBPW=credentials('tieradmin-dockerhub-pw')
}
stages {
stage('Setting build context') {
steps {
script {
maintainer = maintain()
imagename = imagename()
if(env.BRANCH_NAME == "master") {
tag = "latest"
} else {
tag = env.BRANCH_NAME
}
if(!imagename){
echo "You must define an imagename in common.bash"
currentBuild.result = 'FAILURE'
}
sh 'mkdir -p tmp && mkdir -p bin'
dir('tmp'){
git([ url: "https://github.internet2.edu/docker/util.git", credentialsId: "jenkins-github-access-token" ])
sh 'rm -rf ../bin/*'
sh 'mv ./bin/* ../bin/.'
}
}
}
}
stage('Clean') {
steps {
script {
try{
sh 'bin/destroy.sh >> debug'
} catch(error) {
def error_details = readFile('./debug');
def message = "BUILD ERROR: There was a problem building the Base Image. \n\n ${error_details}"
sh "rm -f ./debug"
handleError(message)
}
}
}
}
stage('Build exerciseSets') {
steps {
script {
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 ->
// 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}"
}
}
}
}
stage('Notify') {
steps{
echo "$maintainer"
slackSend color: 'good', message: "${maintainer}/${imagename} version ${tag} pushed to DockerHub"
}
}
}
post {
always {
echo 'Done Building.'
}
failure {
// slackSend color: 'good', message: "Build failed"
handleError("BUILD ERROR: There was a problem building ${maintainer}/${imagename} version ${tag}.")
}
}
}
def maintain() {
def matcher = readFile('common.bash') =~ 'maintainer="(.+)"'
matcher ? matcher[0][1] : 'tier'
}
def imagename() {
def matcher = readFile('common.bash') =~ 'imagename="(.+)"'
matcher ? matcher[0][1] : null
}
def handleError(String message){
echo "${message}"
currentBuild.setResult("FAILED")
slackSend color: 'danger', message: "${message}"
//step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: 'chubing@internet2.edu', sendToIndividuals: true])
sh 'exit 1'
}