Compare commits
11 Commits
Author | SHA1 | Date |
---|---|---|
|
b98e6a99ae | |
|
a2248404cf | |
|
18c0cdda1b | |
|
c9eb592e0a | |
|
1b37d9510d | |
|
6cc6c5ef36 | |
|
008bae5cee | |
|
14cb41d4d9 | |
|
a4e9602ca9 | |
|
93da924aab | |
|
96f4e59cbc |
|
@ -1,7 +1,7 @@
|
||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: buildah
|
- name: buildah
|
||||||
image: quay.io/containers/buildah:v1
|
image: quay.io/containers/buildah:v1.37
|
||||||
command:
|
command:
|
||||||
- cat
|
- cat
|
||||||
stdin: true
|
stdin: true
|
||||||
|
@ -17,3 +17,5 @@ spec:
|
||||||
limits:
|
limits:
|
||||||
github.com/fuse: 1
|
github.com/fuse: 1
|
||||||
hostUsers: false
|
hostUsers: false
|
||||||
|
tolerations:
|
||||||
|
- key: du5t1n.me/jenkins
|
|
@ -1,15 +1,19 @@
|
||||||
// vim: set sw=4 sts=4 ts=4 et :
|
// vim: set sw=4 sts=4 ts=4 et :
|
||||||
|
|
||||||
def call(args) {
|
def call(args) {
|
||||||
properties([
|
|
||||||
pipelineTriggers([cron('H H H * *')])
|
|
||||||
])
|
|
||||||
|
|
||||||
def registry = args?.registry
|
def registry = args?.registry
|
||||||
def project = args?.project
|
def project = args?.project
|
||||||
def name = args?.name
|
def name = args?.name
|
||||||
def tag = args?.tag
|
def tag = args?.tag
|
||||||
def archlist = args?.archlist
|
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) {
|
if (registry == null) {
|
||||||
registry = 'git.pyrocufflink.net'
|
registry = 'git.pyrocufflink.net'
|
||||||
|
@ -18,21 +22,17 @@ def call(args) {
|
||||||
project = 'containerimages'
|
project = 'containerimages'
|
||||||
}
|
}
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
name = env.JOB_NAME.
|
name = escapeImageName(env.JOB_NAME.split('/')[1])
|
||||||
split('/')[1].
|
|
||||||
toLowerCase().
|
|
||||||
replaceAll('[^a-zA-z0-9._-]', '-').
|
|
||||||
replaceAll('^[.-]', '_')
|
|
||||||
}
|
}
|
||||||
if (tag == null) {
|
if (tag == null) {
|
||||||
tag = env.BRANCH_NAME.
|
tag = escapeImageName(env.BRANCH_NAME)
|
||||||
toLowerCase().
|
|
||||||
replaceAll('[^a-zA-z0-9._-]', '-').
|
|
||||||
replaceAll('^[.-]', '_')
|
|
||||||
}
|
}
|
||||||
if (archlist == null) {
|
if (archlist == null) {
|
||||||
archlist = ['amd64']
|
archlist = ['amd64']
|
||||||
}
|
}
|
||||||
|
if (defaultBranch == null) {
|
||||||
|
defaultBranch = 'main'
|
||||||
|
}
|
||||||
def repo = "${registry}/${project}/${name}"
|
def repo = "${registry}/${project}/${name}"
|
||||||
def full_name = "${repo}:${tag}"
|
def full_name = "${repo}:${tag}"
|
||||||
|
|
||||||
|
@ -46,6 +46,7 @@ def call(args) {
|
||||||
full_name: full_name,
|
full_name: full_name,
|
||||||
registry: registry,
|
registry: registry,
|
||||||
arch: arch,
|
arch: arch,
|
||||||
|
resources: resources,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,7 +61,7 @@ def call(args) {
|
||||||
sh "buildah manifest create '${full_name}'"
|
sh "buildah manifest create '${full_name}'"
|
||||||
archlist.each { arch ->
|
archlist.each { arch ->
|
||||||
unstash 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) {
|
if (archlist.size() > 1) {
|
||||||
sh "buildah manifest push --all ${full_name} docker://${full_name}-${env.BUILD_NUMBER}"
|
sh "buildah manifest push --all ${full_name} docker://${full_name}-${env.BUILD_NUMBER}"
|
||||||
sh "buildah manifest push ${full_name} docker://${full_name}"
|
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"
|
sh "buildah manifest push ${full_name} docker://${repo}:latest"
|
||||||
}
|
}
|
||||||
} else {
|
} 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} ${full_name}-${env.BUILD_NUMBER}"
|
||||||
sh "buildah push ${full_name}"
|
sh "buildah push ${full_name}"
|
||||||
if (env.BRANCH_NAME == 'main') {
|
if (env.BRANCH_NAME == defaultBranch) {
|
||||||
sh "buildah push ${full_name} ${repo}:latest"
|
sh "buildah push ${full_name} ${repo}:latest"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,28 +94,41 @@ def buildStage(args) {
|
||||||
def full_name = args.full_name
|
def full_name = args.full_name
|
||||||
def registry = args.registry
|
def registry = args.registry
|
||||||
def arch = args.arch
|
def arch = args.arch
|
||||||
|
def resources = args?.resources
|
||||||
|
|
||||||
runInPod(arch) {
|
runInPod(arch: arch, resources: resources) {
|
||||||
checkout scm
|
checkout scm
|
||||||
|
|
||||||
container('buildah') {
|
container('buildah') {
|
||||||
withBuildahCreds(registry) {
|
withBuildahCreds(registry) {
|
||||||
sh "buildah build -t '${full_name}' ."
|
sh "buildah build -t '${full_name}' ."
|
||||||
sh "buildah push '${full_name}' oci-archive:\${PWD}/${name}-${arch}.tar"
|
sh "buildah push '${full_name}' oci-archive:\${PWD}/${escapeImageName(name)}-${arch}.tar:${full_name}"
|
||||||
stash name: arch, includes: "${name}-*.tar"
|
stash name: arch, includes: "${escapeImageName(name)}-*.tar"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def runInPod(... args) {
|
def runInPod(block) {
|
||||||
def arch = null
|
runInPod(null, block)
|
||||||
def block = args.last()
|
}
|
||||||
if (args.size() > 1) {
|
|
||||||
arch = args[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
def podTemplateYaml = libraryResource('podTemplate-multiarch.yaml')
|
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)
|
||||||
|
}
|
||||||
podTemplate(
|
podTemplate(
|
||||||
yaml: podTemplateYaml,
|
yaml: podTemplateYaml,
|
||||||
nodeSelector: arch ? "kubernetes.io/arch=${arch}" : null,
|
nodeSelector: arch ? "kubernetes.io/arch=${arch}" : null,
|
||||||
|
@ -142,3 +160,10 @@ def withBuildahCreds(registry, block) {
|
||||||
block()
|
block()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def escapeImageName(name) {
|
||||||
|
return name.
|
||||||
|
toLowerCase().
|
||||||
|
replaceAll('[^a-zA-z0-9._-]', '-').
|
||||||
|
replaceAll('^[.-]', '_')
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue