From f02b02bea0cf1a2a53728098736d2d513476b3a7 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Sat, 6 Jan 2024 11:30:19 -0600 Subject: [PATCH] ci: Add Jenkins build pipeline This Jenkins pipeline runs every day and fetches the latest FCOS metadata to determine if a new version of the kernel driver needs to be built. If no container image matching the kernel version in the latest FCOS release exists, it will be built and pushed to the image repository. --- Jenkinsfile | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..cbde8ef --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,62 @@ +// vim: set sw=4 ts=4 sts=4 et : + +properties([ + pipelineTriggers([cron('H H * * *')]) +]) + +import groovy.json.JsonSlurper + +def get_fcos_release(arch) { + def res = httpRequest( + url: 'https://builds.coreos.fedoraproject.org/streams/stable.json', + acceptType: 'APPLICATION_JSON', + ) + def json = new JsonSlurper() + def data = json.parseText(res.getContent()) + return data.architectures[arch].artifacts.metal.release +} + +def get_kernel_version(arch, fcos_release) { + def res = httpRequest( + url: "https://builds.coreos.fedoraproject.org/prod/streams/stable/builds/${fcos_release}/${arch}/commitmeta.json", + acceptType: 'APPLICATION_JSON', + ) + def json = new JsonSlurper() + def data = json.parseText(res.getContent()) + def pkg = data["rpmostree.rpmdb.pkglist"].find { it.getAt(0) == "kernel" } + return "${pkg[2]}-${pkg[3]}.${pkg[4]}" +} + +def check_container_image(kver) { + def res = httpRequest( + url: "https://git.pyrocufflink.net/ContainerImages/-/packages/container/gasket-driver/${kver}", + httpMode: 'HEAD', + validResponseCodes: '100:599', + ) + return res.getStatus() < 300 +} + +def arch = 'x86_64' +def fcos_release = get_fcos_release(arch) +def kver = get_kernel_version(arch, fcos_release) +def fedora = (kver =~ /\.fc([0-9]+)\./)[0][1] +def registry = 'git.pyrocufflink.net' +def full_name = "${registry}/containerimages/gasket-driver:${kver}" +if (!check_container_image(kver)) { + buildContainerImage2.runInPod { + container('buildah') { + buildContainerImage2.withBuildahCreds(registry) { + stage('Build') { + checkout scm + sh "buildah build -t '${full_name}' --build-arg FEDORA='${fedora}' --build-arg KVER='${kver}'" + } + + stage('Push') { + sh "buildah push '${full_name}'" + } + } + } + } +} else { + currentBuild.result = 'NOT_BUILT' +}