Compare commits

..

1 Commits

Author SHA1 Message Date
Dustin 057139ef2d wip: buildContainerImage2 2023-10-05 22:04:47 -05:00
2 changed files with 27 additions and 54 deletions

View File

@ -1,7 +1,7 @@
spec:
containers:
- name: buildah
image: quay.io/containers/buildah:v1.37
image: quay.io/containers/buildah:v1
command:
- cat
stdin: true
@ -17,5 +17,3 @@ spec:
limits:
github.com/fuse: 1
hostUsers: false
tolerations:
- key: du5t1n.me/jenkins

View File

@ -1,19 +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
properties([
pipelineTriggers([cron(schedule ?: 'H H H * *')])
])
if (registry == null) {
registry = 'git.pyrocufflink.net'
@ -22,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}"
@ -46,7 +46,6 @@ def call(args) {
full_name: full_name,
registry: registry,
arch: arch,
resources: resources,
)
}
}
@ -61,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"
}
}
}
@ -69,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"
}
}
@ -94,41 +89,28 @@ def buildStage(args) {
def full_name = args.full_name
def registry = args.registry
def arch = args.arch
def resources = args?.resources
runInPod(arch: arch, resources: resources) {
runInPod(arch) {
checkout scm
container('buildah') {
withBuildahCreds(registry) {
sh "buildah build -t '${full_name}' ."
sh "buildah push '${full_name}' oci-archive:\${PWD}/${escapeImageName(name)}-${arch}.tar:${full_name}"
stash name: arch, includes: "${escapeImageName(name)}-*.tar"
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,
@ -160,10 +142,3 @@ def withBuildahCreds(registry, block) {
block()
}
}
def escapeImageName(name) {
return name.
toLowerCase().
replaceAll('[^a-zA-z0-9._-]', '-').
replaceAll('^[.-]', '_')
}