From 01a5d7692c9de7d505918a5cbd9394ecbbc9b667 Mon Sep 17 00:00:00 2001 From: Saya Andy Date: Mon, 7 Sep 2026 05:22:19 +0700 Subject: initial commit --- Jenkinsfile | 157 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 Jenkinsfile (limited to 'Jenkinsfile') diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..24d235b --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,157 @@ +// Builds are driven by the tag name. The pipeline does nothing at all unless +// the checkout is a tag of the form +// +// fedora--libcamera- +// +// e.g. fedora-45-libcamera-sp12in1. +TAG_PATTERN = /^fedora-(\d+)-libcamera-([a-z0-9]+)$/ + +def fedoraVersionFromTag() { + def tag = env.TAG_NAME ?: '' + tag ==~ TAG_PATTERN ? tag.split('-')[1] : null +} + +pipeline { + agent none + + options { + timestamps() + } + + environment { + B2_ENDPOINT = 'https://s3.eu-central-003.backblazeb2.com' + AWS_DEFAULT_REGION = 'eu-central-003' + + RPM_BUCKET = 'dist-sayagit-fedora-rpm' + + // awscli2 sends CRC32 checksums by default, which B2 rejects. Ask for + // them only where the S3 API requires them. + AWS_REQUEST_CHECKSUM_CALCULATION = 'when_required' + AWS_RESPONSE_CHECKSUM_VALIDATION = 'when_required' + } + + stages { + stage('Build and publish libcamera RPMs (ARM64)') { + when { + beforeAgent true + allOf { + buildingTag() + expression { env.TAG_NAME ==~ TAG_PATTERN } + } + } + + agent { + kubernetes { + defaultContainer 'rpmbuild' + yaml """ +apiVersion: v1 +kind: Pod +metadata: + namespace: jenkins +spec: + nodeSelector: + kubernetes.io/arch: arm64 + containers: + - name: rpmbuild + image: fedora:${fedoraVersionFromTag()} + imagePullPolicy: Always + command: [ 'sleep' ] + args: [ 'infinity' ] + tty: true + resources: + requests: + cpu: "4" + memory: 4Gi + ephemeral-storage: 10Gi + limits: + memory: 8Gi + ephemeral-storage: 30Gi +""" + } + } + steps { + checkout scm + container('rpmbuild') { + withCredentials([usernamePassword( + credentialsId: 'backblaze-b2-dist-rpm', + usernameVariable: 'AWS_ACCESS_KEY_ID', + passwordVariable: 'AWS_SECRET_ACCESS_KEY')]) { + sh ''' + set -eux + + dnf --assumeyes install \\ + git rpm-build rpmdevtools dnf5-plugins awscli2 curl \\ + createrepo_c + + git config --global --add safe.directory '*' + + tag_fedora=${TAG_NAME#fedora-} + tag_fedora=${tag_fedora%%-libcamera-*} + tag_suffix=${TAG_NAME##*-libcamera-} + fedora_version=${tag_fedora} + + export RELEASE_SUFFIX=${tag_suffix} + + # A numbered tag has to agree with the container it + # selected, which is what stamps %{?dist} onto the + # release. + container_fedora=$(rpm --eval '%{fedora}') + if [ "${tag_fedora}" != "${container_fedora}" ]; then + echo "tag names Fedora ${tag_fedora}, container is ${container_fedora}" >&2 + exit 1 + fi + + work="${WORKSPACE}/work" + out="${WORKSPACE}/rpms" + prefix="s3://${RPM_BUCKET}/fedora/${fedora_version}/aarch64" + + # Resolving is a source-RPM download and a couple of + # spec edits, so ask what the build would produce + # before paying for the build itself. + rpm_files=$(./build.sh -n -w "${work}") + + missing=false + for rpm_name in ${rpm_files}; do + if ! aws s3 ls --endpoint-url "${B2_ENDPOINT}" \\ + "${prefix}/${rpm_name}"; then + missing=true + fi + done + + if [ "${missing}" = false ]; then + echo "${TAG_NAME} is already published in full, nothing to do" + exit 0 + fi + + ./build.sh -o "${out}" -w "${work}" + + # Every subpackage goes up, not just the two the + # image needs: Fedora's libcamera-qcam and the rest + # carry a versioned Requires on this exact release, + # so a partial set would leave them unresolvable. + for rpm_name in ${rpm_files}; do + aws s3 cp --endpoint-url "${B2_ENDPOINT}" \\ + "${out}/${rpm_name}" "${prefix}/${rpm_name}" + done + + repo="${WORKSPACE}/repo" + mkdir -p "${repo}" + aws s3 sync --endpoint-url "${B2_ENDPOINT}" \\ + --exclude '*' --include '*.rpm' \\ + "${prefix}/" "${repo}/" + + createrepo_c --update "${repo}" + + aws s3 sync --endpoint-url "${B2_ENDPOINT}" \\ + --exclude 'repomd.xml*' \\ + "${repo}/repodata/" "${prefix}/repodata/" + aws s3 cp --endpoint-url "${B2_ENDPOINT}" \\ + "${repo}/repodata/repomd.xml" \\ + "${prefix}/repodata/repomd.xml" + ''' + } + } + } + } + } +} -- cgit v1.3.1+17