diff --git a/resources/fedoraBuild/podTemplate.yaml b/resources/fedoraBuild/podTemplate.yaml new file mode 100644 index 0000000..43072a0 --- /dev/null +++ b/resources/fedoraBuild/podTemplate.yaml @@ -0,0 +1,8 @@ +spec: + containers: + - name: build + command: + - cat + stdin: true + tty: true + hostUsers: false diff --git a/vars/fedoraBuild.groovy b/vars/fedoraBuild.groovy new file mode 100644 index 0000000..cb91251 --- /dev/null +++ b/vars/fedoraBuild.groovy @@ -0,0 +1,70 @@ +def call(block) { + call(null, block) +} + +def call(args, block) { + def podTemplateFile = args?.podTemplate + def architectures = args?.architectures + def buildContainer = args?.buildContainer ?: 'build' + def containerImage = args?.containerImage + if (architectures == null) { + architectures = ['amd64', 'arm64'] + } + + def podTemplateYaml + if (podTemplateFile == null) { + podTemplateYaml = libraryResource('fedoraBuild/podTemplate.yaml') + } else { + podTemplateYaml = readTrusted(podTemplateFile) + } + + def versions = getVersions() + matrixBuild(architectures, versions) { arch, fedoraVersion -> + def tmpl = readYaml(text: podTemplateYaml) + tmpl.spec.containers.each { container -> + if (container.name == buildContainer) { + if (containerImage == null) { + container.image = "registry.fedoraproject.org/fedora:${fedoraVersion}" + } else if (containerImage instanceof String) { + container.image = containerImage + } else { + container.image = containerImage(arch, fedoraVersion) + } + } + } + podTemplate( + yaml: writeYaml(data: tmpl, returnText: true), + yamlMergeStrategy: merge(), + nodeSelector: "kubernetes.io/arch=${arch}" + ) { + node(POD_LABEL) { + env.FEDORA = fedoraVersion + block(arch, fedoraVersion) + } + } + } +} + +def getVersions() { + def response = httpRequest( + url: 'https://bodhi.fedoraproject.org/releases?state=current', + acceptType: 'APPLICATION_JSON', + ) + def content = readJSON(text: response.content) + return content.releases. + findAll { it.id_prefix == "FEDORA" }. + collect { it.version } +} + +def matrixBuild(architectures, fedoraVersions, block) { + echo "Building for Fedora ${fedoraVersions}, architectures ${architectures}" + parallel architectures.collectMany { arch -> + fedoraVersions.collect { version -> + [arch, version] + } + }.collectEntries { + def arch = it[0] + def version = it[1] + ["f${version}/${arch}", { block(arch, version) }] + } +}