Compare commits
1 Commits
Author | SHA1 | Date |
---|---|---|
|
057139ef2d |
|
@ -1,7 +1,7 @@
|
||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: buildah
|
- name: buildah
|
||||||
image: quay.io/containers/buildah:v1.37
|
image: quay.io/containers/buildah:v1
|
||||||
command:
|
command:
|
||||||
- cat
|
- cat
|
||||||
stdin: true
|
stdin: true
|
||||||
|
@ -17,5 +17,3 @@ spec:
|
||||||
limits:
|
limits:
|
||||||
github.com/fuse: 1
|
github.com/fuse: 1
|
||||||
hostUsers: false
|
hostUsers: false
|
||||||
tolerations:
|
|
||||||
- key: du5t1n.me/jenkins
|
|
|
@ -1,19 +1,15 @@
|
||||||
// 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'
|
||||||
|
@ -22,17 +18,21 @@ def call(args) {
|
||||||
project = 'containerimages'
|
project = 'containerimages'
|
||||||
}
|
}
|
||||||
if (name == null) {
|
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) {
|
if (tag == null) {
|
||||||
tag = escapeImageName(env.BRANCH_NAME)
|
tag = 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,7 +46,6 @@ def call(args) {
|
||||||
full_name: full_name,
|
full_name: full_name,
|
||||||
registry: registry,
|
registry: registry,
|
||||||
arch: arch,
|
arch: arch,
|
||||||
resources: resources,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,7 +60,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}/${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) {
|
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 == defaultBranch) {
|
if (env.BRANCH_NAME == 'main') {
|
||||||
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 == defaultBranch) {
|
if (env.BRANCH_NAME == 'main') {
|
||||||
sh "buildah push ${full_name} ${repo}:latest"
|
sh "buildah push ${full_name} ${repo}:latest"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,41 +89,28 @@ 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: arch, resources: resources) {
|
runInPod(arch) {
|
||||||
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}/${escapeImageName(name)}-${arch}.tar:${full_name}"
|
sh "buildah push '${full_name}' oci-archive:\${PWD}/${name}-${arch}.tar"
|
||||||
stash name: arch, includes: "${escapeImageName(name)}-*.tar"
|
stash name: arch, includes: "${name}-*.tar"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def runInPod(block) {
|
def runInPod(... args) {
|
||||||
runInPod(null, block)
|
def arch = null
|
||||||
|
def block = args.last()
|
||||||
|
if (args.size() > 1) {
|
||||||
|
arch = args[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
def runInPod(args, block) {
|
def podTemplateYaml = libraryResource('podTemplate-multiarch.yaml')
|
||||||
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,
|
||||||
|
@ -160,10 +142,3 @@ def withBuildahCreds(registry, block) {
|
||||||
block()
|
block()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def escapeImageName(name) {
|
|
||||||
return name.
|
|
||||||
toLowerCase().
|
|
||||||
replaceAll('[^a-zA-z0-9._-]', '-').
|
|
||||||
replaceAll('^[.-]', '_')
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue