|
|
|
|
@@ -1,20 +1,15 @@
|
|
|
|
|
// vim: set sw=4 sts=4 ts=4 et :
|
|
|
|
|
|
|
|
|
|
def call(args) {
|
|
|
|
|
properties([
|
|
|
|
|
pipelineTriggers([cron('H H H * *')])
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
def registry = args?.registry
|
|
|
|
|
def project = args?.project
|
|
|
|
|
def name = args?.name
|
|
|
|
|
def tag = args?.tag
|
|
|
|
|
def archlist = args?.archlist
|
|
|
|
|
def schedule = args?.schedule
|
|
|
|
|
def defaultBranch = args?.defaultBranch
|
|
|
|
|
def pi = args?.pi
|
|
|
|
|
def resources = args?.resources
|
|
|
|
|
def buildArgs = args?.buildArgs
|
|
|
|
|
|
|
|
|
|
properties([
|
|
|
|
|
pipelineTriggers([cron(schedule ?: 'H H H * *')])
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
if (registry == null) {
|
|
|
|
|
registry = 'git.pyrocufflink.net'
|
|
|
|
|
@@ -23,17 +18,21 @@ def call(args) {
|
|
|
|
|
project = 'containerimages'
|
|
|
|
|
}
|
|
|
|
|
if (name == null) {
|
|
|
|
|
name = escapeImageName(env.JOB_NAME.split('/')[1])
|
|
|
|
|
name = env.JOB_NAME.
|
|
|
|
|
split('/')[1].
|
|
|
|
|
toLowerCase().
|
|
|
|
|
replaceAll('[^a-zA-z0-9._-]', '-').
|
|
|
|
|
replaceAll('^[.-]', '_')
|
|
|
|
|
}
|
|
|
|
|
if (tag == null) {
|
|
|
|
|
tag = escapeImageName(env.BRANCH_NAME)
|
|
|
|
|
tag = env.BRANCH_NAME.
|
|
|
|
|
toLowerCase().
|
|
|
|
|
replaceAll('[^a-zA-z0-9._-]', '-').
|
|
|
|
|
replaceAll('^[.-]', '_')
|
|
|
|
|
}
|
|
|
|
|
if (archlist == null) {
|
|
|
|
|
archlist = ['amd64']
|
|
|
|
|
}
|
|
|
|
|
if (defaultBranch == null) {
|
|
|
|
|
defaultBranch = 'main'
|
|
|
|
|
}
|
|
|
|
|
def repo = "${registry}/${project}/${name}"
|
|
|
|
|
def full_name = "${repo}:${tag}"
|
|
|
|
|
|
|
|
|
|
@@ -47,8 +46,6 @@ def call(args) {
|
|
|
|
|
full_name: full_name,
|
|
|
|
|
registry: registry,
|
|
|
|
|
arch: arch,
|
|
|
|
|
resources: resources,
|
|
|
|
|
buildArgs: buildArgs,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -63,7 +60,7 @@ def call(args) {
|
|
|
|
|
sh "buildah manifest create '${full_name}'"
|
|
|
|
|
archlist.each { arch ->
|
|
|
|
|
unstash arch
|
|
|
|
|
sh "buildah manifest add '${full_name}' oci-archive:\${PWD}/${escapeImageName(name)}-${arch}.tar:${full_name}"
|
|
|
|
|
sh "buildah manifest add '${full_name}' oci-archive:\${PWD}/${name}-${arch}.tar"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -71,17 +68,13 @@ def call(args) {
|
|
|
|
|
if (archlist.size() > 1) {
|
|
|
|
|
sh "buildah manifest push --all ${full_name} docker://${full_name}-${env.BUILD_NUMBER}"
|
|
|
|
|
sh "buildah manifest push ${full_name} docker://${full_name}"
|
|
|
|
|
if (env.BRANCH_NAME == defaultBranch) {
|
|
|
|
|
if (env.BRANCH_NAME == 'main') {
|
|
|
|
|
sh "buildah manifest push ${full_name} docker://${repo}:latest"
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
archlist.each { arch ->
|
|
|
|
|
unstash arch
|
|
|
|
|
sh "buildah pull oci-archive:\${PWD}/${escapeImageName(name)}-${arch}.tar:${full_name}"
|
|
|
|
|
}
|
|
|
|
|
sh "buildah push ${full_name} ${full_name}-${env.BUILD_NUMBER}"
|
|
|
|
|
sh "buildah push ${full_name}"
|
|
|
|
|
if (env.BRANCH_NAME == defaultBranch) {
|
|
|
|
|
if (env.BRANCH_NAME == 'main') {
|
|
|
|
|
sh "buildah push ${full_name} ${repo}:latest"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -96,46 +89,28 @@ def buildStage(args) {
|
|
|
|
|
def full_name = args.full_name
|
|
|
|
|
def registry = args.registry
|
|
|
|
|
def arch = args.arch
|
|
|
|
|
def resources = args?.resources
|
|
|
|
|
def buildArgs = args?.buildArgs ?: []
|
|
|
|
|
|
|
|
|
|
def build_command = "buildah build -t '${full_name}'"
|
|
|
|
|
buildArgs.each { build_command += "--build-arg '${it}'" }
|
|
|
|
|
build_command += ' .'
|
|
|
|
|
|
|
|
|
|
runInPod(arch: arch, resources: resources) {
|
|
|
|
|
runInPod(arch) {
|
|
|
|
|
checkout scm
|
|
|
|
|
|
|
|
|
|
container('buildah') {
|
|
|
|
|
withBuildahCreds(registry) {
|
|
|
|
|
sh build_command
|
|
|
|
|
sh "buildah push '${full_name}' oci-archive:\${PWD}/${escapeImageName(name)}-${arch}.tar:${full_name}"
|
|
|
|
|
stash name: arch, includes: "${escapeImageName(name)}-*.tar"
|
|
|
|
|
sh "buildah build -t '${full_name}' ."
|
|
|
|
|
sh "buildah push '${full_name}' oci-archive:\${PWD}/${name}-${arch}.tar"
|
|
|
|
|
stash name: arch, includes: "${name}-*.tar"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def runInPod(block) {
|
|
|
|
|
runInPod(null, block)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def runInPod(args, block) {
|
|
|
|
|
def arch = args?.arch
|
|
|
|
|
def resources = args?.resources
|
|
|
|
|
|
|
|
|
|
def podTemplateYaml = libraryResource('podTemplate2.yaml')
|
|
|
|
|
if (resources) {
|
|
|
|
|
def tmpl = readYaml(text: podTemplateYaml)
|
|
|
|
|
tmpl.spec.containers.each { c ->
|
|
|
|
|
c.resources = c.resources ?: [:]
|
|
|
|
|
c.resources.putAll([
|
|
|
|
|
requests: (c.resources.requests ?: [:]) + resources,
|
|
|
|
|
limits: (c.resources.limits ?: [:]) + resources,
|
|
|
|
|
])
|
|
|
|
|
}
|
|
|
|
|
podTemplateYaml = writeYaml(data: tmpl, returnText: true)
|
|
|
|
|
def runInPod(... args) {
|
|
|
|
|
def arch = null
|
|
|
|
|
def block = args.last()
|
|
|
|
|
if (args.size() > 1) {
|
|
|
|
|
arch = args[0]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def podTemplateYaml = libraryResource('podTemplate-multiarch.yaml')
|
|
|
|
|
podTemplate(
|
|
|
|
|
yaml: podTemplateYaml,
|
|
|
|
|
nodeSelector: arch ? "kubernetes.io/arch=${arch}" : null,
|
|
|
|
|
@@ -167,10 +142,3 @@ def withBuildahCreds(registry, block) {
|
|
|
|
|
block()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def escapeImageName(name) {
|
|
|
|
|
return name.
|
|
|
|
|
toLowerCase().
|
|
|
|
|
replaceAll('[^a-zA-z0-9._-]', '-').
|
|
|
|
|
replaceAll('^[.-]', '_')
|
|
|
|
|
}
|
|
|
|
|
|