You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
213 lines
7.4 KiB
213 lines
7.4 KiB
// Jenkins file to build our dev docker images based on alpine, debian & ubuntu |
|
properties( [ |
|
buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '7', numToKeepStr: '10')), |
|
disableConcurrentBuilds(), |
|
disableResume(), |
|
pipelineTriggers([cron('H H * * *')]) |
|
]) |
|
|
|
// Repository name use, must end with / or be '' for none |
|
repository= 'docker.ceres.area51.dev/area51/' |
|
|
|
// What we need to build |
|
targetDefs = [ |
|
[ |
|
name: 'alpine', |
|
versions: [ 'edge' ], |
|
images: [ 'base', 'dev' ], |
|
architectures: [ 'amd64', 'arm64v8' ] |
|
],[ |
|
name: "debian", |
|
versions: [ '10' ], |
|
images: [ 'base', 'dev', 'php' ], |
|
architectures: [ 'amd64', 'arm64v8' ] |
|
],[ |
|
name: 'ubuntu', |
|
versions: [ '18.04', '20.04' ], |
|
images: [ 'base', 'dev' ], |
|
architectures: [ 'amd64', 'arm64v8', "arm32v7" ] |
|
],[ |
|
name: 'ubuntu', |
|
versions: [ '20.04' ], |
|
images: [ 'node', 'chromium' ], |
|
architectures: [ 'amd64', 'arm64v8', "arm32v7" ] |
|
/* |
|
],[ |
|
name: 'ubuntu', |
|
versions: [ '20.04' ], |
|
images: [ "armhf", "arm64" ], |
|
architectures: [ 'amd64' ] |
|
*/ |
|
] |
|
] |
|
|
|
// Break down targetDefs so each image is built in sequence. We will then parallel build each one |
|
|
|
// images is a list of image names in order they are found, used to determine the build order |
|
images = [] |
|
|
|
// map of image name & targets to build for that image |
|
imageName = [:] |
|
|
|
// resolve the build order |
|
targetDefs.each { |
|
target -> target.images.each { |
|
image -> L:{ |
|
if( !imageName.containsKey( image ) ) { |
|
imageName[image] = [] |
|
images << image |
|
} |
|
|
|
imageName[image] << [ |
|
name: target.name, |
|
versions: target.versions, |
|
images: [ image ], |
|
architectures: target.architectures |
|
] |
|
} |
|
} |
|
} |
|
|
|
// create targets list based on the image order |
|
targets = [] |
|
images.each { |
|
image -> targets << imageName[image] |
|
} |
|
|
|
// The docker tag name: architecture can be '' for multiarch images |
|
def dockerTag = { |
|
name, image, version, architecture -> name + ':' + |
|
image + '-' + version + |
|
( architecture=='' ? '' : ( '-' + architecture ) ) |
|
} |
|
|
|
// The docker image name: architecture can be '' for multiarch images |
|
def dockerImage = { |
|
name, image, version, architecture -> repository + dockerTag( name, image, version, architecture ) |
|
} |
|
|
|
// The go arch |
|
def goarch = { |
|
architecture -> switch( architecture ) { |
|
case 'amd64': |
|
return 'amd64' |
|
case 'arm32v6': |
|
case 'arm32v7': |
|
return 'arm' |
|
case 'arm64v8': |
|
return 'arm64' |
|
default: |
|
return architecture |
|
} |
|
} |
|
|
|
// The go arch variant |
|
def govariant = { |
|
architecture -> switch( architecture ) { |
|
case 'amd64': |
|
return '' |
|
case 'arm32v6': |
|
return '--variant v6' |
|
case 'arm32v7': |
|
return '--variant v7' |
|
case 'arm64v8': |
|
return '' |
|
default: |
|
return '' |
|
} |
|
} |
|
|
|
// Build the targets |
|
targets.each { |
|
round -> L:{ |
|
// Build the tasks for this image |
|
tasks = [:] |
|
multiTasks = [:] |
|
|
|
round.each { |
|
target -> L:{ |
|
// Each image target in sequence |
|
target.images.each { |
|
img -> L:{ |
|
// Each version in sequence |
|
for( ver in target.versions) { |
|
// Need to bind before closure to ensure they don't change with the next image/version |
|
def name = target.name |
|
def image = img |
|
def version = ver |
|
|
|
for( arch in target.architectures) { |
|
// Need to bind before closure again |
|
def architecture = arch |
|
def tag = dockerImage( name, image, version, architecture ) |
|
tasks[dockerTag( name, image, version, architecture )] = { |
|
node( architecture ) { |
|
stage( architecture ) { |
|
checkout scm |
|
|
|
sh 'docker build' + |
|
' --pull' + |
|
' -t ' + tag + |
|
' --build-arg version=' + version + |
|
' -f ' + [name, image, 'Dockerfile'].join( '/' ) + |
|
' .' |
|
|
|
sh 'docker push ' + tag |
|
} |
|
} |
|
} |
|
} |
|
|
|
// MultiArch image |
|
def multiImage = dockerImage( name, image, version, '' ) |
|
def multiTag = dockerTag( name, image, version, '' ) |
|
def multiArchitectures = target.architectures |
|
def multiImages = [] |
|
multiArchitectures.each { |
|
architecture -> L:{ |
|
multiImages << dockerImage( name, image, version, architecture ) |
|
} |
|
} |
|
|
|
multiTasks[ multiTag ] = { |
|
node( 'amd64' ) { |
|
stage( target.name + '-' + image + ' MultiArch' ) { |
|
|
|
multiArchitectures.each { |
|
architecture -> sh 'docker pull ' + dockerImage( name, image, version, architecture ) |
|
} |
|
|
|
sh 'docker manifest create ' + multiImage + ' ' + multiImages.join(' ') |
|
|
|
multiArchitectures.each { |
|
architecture -> sh 'docker manifest annotate' + |
|
' --os linux' + |
|
' --arch ' + goarch( architecture ) + ' ' + govariant( architecture ) + |
|
' ' + multiImage + |
|
' ' + dockerImage( name, image, version, architecture ) |
|
} |
|
|
|
sh 'docker manifest push -p ' + multiImage |
|
} |
|
} |
|
} |
|
|
|
} // version |
|
} |
|
} |
|
} |
|
} // target |
|
|
|
roundName = round[0].images[0] |
|
|
|
// Run builds in parallel then multi-arch builds |
|
stage( roundName + " build" ) { |
|
parallel tasks |
|
} |
|
|
|
stage( roundName + " multiarch") { |
|
parallel multiTasks |
|
} |
|
|
|
} // round |
|
} // rounds
|
|
|