|
|
|
|
@@ -1,15 +1,19 @@
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
|
|
properties([
|
|
|
|
|
pipelineTriggers([cron(schedule ?: 'H H H * *')])
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
if (registry == null) {
|
|
|
|
|
registry = 'git.pyrocufflink.net'
|
|
|
|
|
@@ -18,21 +22,17 @@ def call(args) {
|
|
|
|
|
project = 'containerimages'
|
|
|
|
|
}
|
|
|
|
|
if (name == null) {
|
|
|
|
|
name = env.JOB_NAME.
|
|
|
|
|
split('/')[1].
|
|
|
|
|
toLowerCase().
|
|
|
|
|
replaceAll('[^a-zA-z0-9._-]', '-').
|
|
|
|
|
replaceAll('^[.-]', '_')
|
|
|
|
|
name = escapeImageName(env.JOB_NAME.split('/')[1])
|
|
|
|
|
}
|
|
|
|
|
if (tag == null) {
|
|
|
|
|
tag = env.BRANCH_NAME.
|
|
|
|
|
toLowerCase().
|
|
|
|
|
replaceAll('[^a-zA-z0-9._-]', '-').
|
|
|
|
|
replaceAll('^[.-]', '_')
|
|
|
|
|
tag = escapeImageName(env.BRANCH_NAME)
|
|
|
|
|
}
|
|
|
|
|
if (archlist == null) {
|
|
|
|
|
archlist = ['amd64']
|
|
|
|
|
}
|
|
|
|
|
if (defaultBranch == null) {
|
|
|
|
|
defaultBranch = 'main'
|
|
|
|
|
}
|
|
|
|
|
def repo = "${registry}/${project}/${name}"
|
|
|
|
|
def full_name = "${repo}:${tag}"
|
|
|
|
|
|
|
|
|
|
@@ -46,6 +46,7 @@ def call(args) {
|
|
|
|
|
full_name: full_name,
|
|
|
|
|
registry: registry,
|
|
|
|
|
arch: arch,
|
|
|
|
|
resources: resources,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -60,7 +61,7 @@ def call(args) {
|
|
|
|
|
sh "buildah manifest create '${full_name}'"
|
|
|
|
|
archlist.each { arch ->
|
|
|
|
|
unstash arch
|
|
|
|
|
sh "buildah manifest add '${full_name}' oci-archive:\${PWD}/${name}-${arch}.tar"
|
|
|
|
|
sh "buildah manifest add '${full_name}' oci-archive:\${PWD}/${escapeImageName(name)}-${arch}.tar:${full_name}"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -68,13 +69,17 @@ 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 == 'main') {
|
|
|
|
|
if (env.BRANCH_NAME == defaultBranch) {
|
|
|
|
|
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 == 'main') {
|
|
|
|
|
if (env.BRANCH_NAME == defaultBranch) {
|
|
|
|
|
sh "buildah push ${full_name} ${repo}:latest"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -89,28 +94,38 @@ def buildStage(args) {
|
|
|
|
|
def full_name = args.full_name
|
|
|
|
|
def registry = args.registry
|
|
|
|
|
def arch = args.arch
|
|
|
|
|
def resources = args?.resources
|
|
|
|
|
|
|
|
|
|
runInPod(arch) {
|
|
|
|
|
runInPod(arch: arch, resources: resources) {
|
|
|
|
|
checkout scm
|
|
|
|
|
|
|
|
|
|
container('buildah') {
|
|
|
|
|
withBuildahCreds(registry) {
|
|
|
|
|
sh "buildah build -t '${full_name}' ."
|
|
|
|
|
sh "buildah push '${full_name}' oci-archive:\${PWD}/${name}-${arch}.tar"
|
|
|
|
|
stash name: arch, includes: "${name}-*.tar"
|
|
|
|
|
sh "buildah push '${full_name}' oci-archive:\${PWD}/${escapeImageName(name)}-${arch}.tar:${full_name}"
|
|
|
|
|
stash name: arch, includes: "${escapeImageName(name)}-*.tar"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def runInPod(... args) {
|
|
|
|
|
def arch = null
|
|
|
|
|
def block = args.last()
|
|
|
|
|
if (args.size() > 1) {
|
|
|
|
|
arch = args[0]
|
|
|
|
|
}
|
|
|
|
|
def runInPod(args, block) {
|
|
|
|
|
def arch = args?.arch
|
|
|
|
|
def resources = args?.resources
|
|
|
|
|
|
|
|
|
|
def podTemplateYaml = libraryResource('podTemplate-multiarch.yaml')
|
|
|
|
|
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.requests ?: [:]) + resources,
|
|
|
|
|
])
|
|
|
|
|
}
|
|
|
|
|
podTemplateYaml = writeYaml(data: tmpl, returnText: true)
|
|
|
|
|
echo podTemplateYaml
|
|
|
|
|
}
|
|
|
|
|
podTemplate(
|
|
|
|
|
yaml: podTemplateYaml,
|
|
|
|
|
nodeSelector: arch ? "kubernetes.io/arch=${arch}" : null,
|
|
|
|
|
@@ -142,3 +157,10 @@ def withBuildahCreds(registry, block) {
|
|
|
|
|
block()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def escapeImageName(name) {
|
|
|
|
|
return name.
|
|
|
|
|
toLowerCase().
|
|
|
|
|
replaceAll('[^a-zA-z0-9._-]', '-').
|
|
|
|
|
replaceAll('^[.-]', '_')
|
|
|
|
|
}
|
|
|
|
|
|