From f3fffa9e4bc92c16739345191d0614756ab1d47a Mon Sep 17 00:00:00 2001 From: Greg Cymbalski Date: Wed, 26 Nov 2025 18:26:28 -0800 Subject: [PATCH] WIP: Tooling to build all kversions, needs major refactoring before pushing --- build-all.sh | 15 +++ build-minor.sh | 26 +++++ build-packages.sh | 222 ++++++++++++++++++++++++++++++++++++++ kmod/scoutfs-kmod.spec.in | 15 +-- 4 files changed, 271 insertions(+), 7 deletions(-) create mode 100644 build-all.sh create mode 100644 build-minor.sh create mode 100644 build-packages.sh diff --git a/build-all.sh b/build-all.sh new file mode 100644 index 00000000..a495d33e --- /dev/null +++ b/build-all.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +export EL_VER +export IS_EDGE + +# 'edge' releases first' +for EL_VER in 8.10 9.6; do + IS_EDGE=1 + bash ./build-minor.sh +done + +# then legacy +for EL_VER in 8.9 9.4 9.5; do + bash ./build-minor.sh +done diff --git a/build-minor.sh b/build-minor.sh new file mode 100644 index 00000000..7ee7536d --- /dev/null +++ b/build-minor.sh @@ -0,0 +1,26 @@ +#!/bin/bash +set -x + +export EL_MAJOR_VER="${EL_MAJOR_VER:-9.4}" +export EL_VER="${EL_VER:-${EL_MAJOR_VER}}" +export MAJOR_VER="${EL_VER%%.*}" +export MINOR_VER="${EL_VER#*.}" +export RELEASE="${RELEASE:-0}" +export IS_EDGE="${IS_EDGE:-0}" + +for KVER in $(bash build-packages.sh get-kvers); do + echo "Building for ${KVER} on ${EL_VER}" + docker run --rm --privileged \ + -e "VERBOSE=0" \ + -e "KVERSION=${KVER}" \ + -e "EL_VER=${EL_VER}" \ + -e "RELEASE=${RELEASE}" \ + -e "HTTP_PROXY=http://package-mirror.vpn.versity.com:3128" \ + -e "IS_EDGE=${IS_EDGE}" \ + -v "/var/cache:/var/cache" \ + -v "/run/containers/storage:/run/containers/storage" \ + -v "/var/lib/containers/storage:/var/lib/containers/storage" \ + -v .:/repo \ + "scoutfs-builder:el${EL_VER}" \ + bash -c "cd /repo && git config --global --add safe.directory /repo && bash build-packages.sh && chown -R ${UID} /repo" +done diff --git a/build-packages.sh b/build-packages.sh new file mode 100644 index 00000000..4ea7d1b2 --- /dev/null +++ b/build-packages.sh @@ -0,0 +1,222 @@ +#!/bin/bash +set -ex + + +export EL_MAJOR_VER="${EL_MAJOR_VER:-9.5}" +export EL_VER="${EL_VER:-${EL_MAJOR_VER}}" +export MAJOR_VER="${EL_VER%%.*}" +export MINOR_VER="${EL_VER#*.}" + +IS_EDGE="${IS_EDGE:-0}" +VERBOSE="${VERBOSE:-1}" + +mock_args=() + +if [ "${VERBOSE}" -eq 1 ]; then + mock_args+=(-v) +else + mock_args+=(-q) +fi + +function get_kvers { + REPO_PATH="$1" + curl "${REPO_PATH}/devel/x86_64/os/Packages/k/" | \ + grep -e 'kernel-devel-[0-9]' | \ + grep -o 'href="[^"]*\.rpm"' | \ + cut -d'"' -f2 | \ + sed -e 's/^[a-z-]*//g' | \ + sed -e 's/\.el.*//g' | \ + sort -V +} + +function get_latest_kver { + get_kvers "$1" | tail -n1 +} + +function get_oldest_kver { + get_kvers "$1" | head -n1 +} + +function repo_addr { + REPO_BASE="$1" + REPO_NAME="$2" + echo "${REPO_BASE}/${REPO_NAME}/x86_64/os/" +} + +RELEASE=${RELEASE:-0} +if [ "${RELEASE}" == "1" ]; then + RELEASE_OPT=(--define "_release ${RELEASE}") +else + RELEASE_OPT=() +fi + +if [ "${IS_EDGE}" -eq 1 ]; then + REPO_ROOT_PATH="pub" +else + REPO_ROOT_PATH="vault" +fi + +REPO_BASE="http://download.rockylinux.org/${REPO_ROOT_PATH}/rocky/${EL_VER}" + +# if we haven't injected the KVERSION we want into the env, detect it based on the repo path +if [ -z "${KVERSION}" ]; then + if [ "${REPO_ROOT_PATH}" = "pub" ]; then + # unfortunately we HAVE to use the latest version + KVERSION="$(get_latest_kver "${REPO_BASE}")" + else + KVERSION="$(get_oldest_kver "${REPO_BASE}")" + fi +fi + +if [[ "${1}" == 'get-kvers' ]]; then + get_kvers "${REPO_BASE}" + exit 0 +fi + +echo "Starting Build $BUILD_DISPLAY_NAME on $NODE_NAME" + +(git repack -a -d && rm .git/objects/info/alternates) || true + +cat <scoutfs-build-${EL_VER}.cfg +config_opts['root'] = 'rocky-${EL_VER}-base-x86_64' +config_opts['target_arch'] = 'x86_64' +config_opts['legal_host_arches'] = ('x86_64',) +config_opts['chroot_setup_cmd'] = 'install tar gcc-c++ redhat-rpm-config redhat-release which xz sed make bzip2 gzip gcc coreutils unzip shadow-utils diffutils cpio bash gawk rpm-build info patch util-linux findutils grep systemd sparse' +config_opts['dist'] = 'el${MAJOR_VER}' # only useful for --resultdir variable subst +config_opts['releasever'] = '${MAJOR_VER}' +config_opts['package_manager'] = 'dnf' +config_opts['extra_chroot_dirs'] = [ '/run/lock', ] +config_opts['bootstrap_image'] = "quay.io/rockylinux/rockylinux:${EL_VER}" +config_opts['description'] = "Rocky Linux ${EL_VER}" +config_opts['http_proxy'] = 'http://package-mirror.vpn.versity.com:3128' + +# experiment: simplify for better docker use +config_opts['use_nspawn'] = False +config_opts['isolation'] = 'simple' +config_opts['plugin_conf']['root_cache_enable'] = True +config_opts['plugin_conf']['yum_cache_enable'] = True +config_opts['plugin_conf']['dnf_cache_enable'] = True + +config_opts['dnf.conf'] = """ +[main] +keepcache=1 +debuglevel=2 +reposdir=/dev/null +logfile=/var/log/yum.log +retries=20 +obsoletes=1 +gpgcheck=0 +assumeyes=1 +syslog_ident=mock +syslog_device= +metadata_expire=0 +mdpolicy=group:primary +best=1 +install_weak_deps=0 +protected_packages= +module_platform_id=platform:el${MAJOR_VER} +user_agent={{ user_agent }} + +# repos +[baseos] +name=Rocky Linux ${EL_VER} - BaseOS +repo=rocky-BaseOS-${EL_VER}&arch=x86_64 +baseurl=$(repo_addr "${REPO_BASE}" "BaseOS") +gpgcheck=0 +enabled=1 +gpgkey=file:///usr/share/distribution-gpg-keys/rocky/RPM-GPG-KEY-Rocky-${MAJOR_VER} + +[appstream] +name=Rocky Linux ${EL_VER} - AppStream +baseurl=$(repo_addr "${REPO_BASE}" "AppStream") +gpgcheck=0 +enabled=1 +gpgkey=file:///usr/share/distribution-gpg-keys/rocky/RPM-GPG-KEY-Rocky-${MAJOR_VER} + +[devel] +name=Rocky Linux ${EL_VER} - Devel +repo=rocky-Devel-${EL_VER}&arch=x86_64 +baseurl=$(repo_addr "${REPO_BASE}" "devel") +gpgcheck=0 +enabled=1 +gpgkey=file:///usr/share/distribution-gpg-keys/rocky/RPM-GPG-KEY-Rocky-${MAJOR_VER} + +[epel] +name=EPEL - \$releasever +baseurl=https://dl.fedoraproject.org/pub/epel/\$releasever/Everything/x86_64/ +gpgcheck=0 +enabled=1 +""" +EOF + +cd "${WORKSPACE:-.}" + +sudo mkdir -p /usr/share/distribution-gpg-keys/rocky/ +sudo curl -o "/usr/share/distribution-gpg-keys/rocky/RPM-GPG-KEY-Rocky-${MAJOR_VER}" https://download.rockylinux.org/pub/rocky/RPM-GPG-KEY-Rocky-${MAJOR_VER} + +# make kmod rpms +pushd kmod +rm kmod-scoutfs.spec || true +make dist +if [ "$?" -ne "0" ]; then + exit 1 +fi + +sleep 5s + +try=0 +while [[ "$try" -lt "3" ]]; do + echo "Trying to build srpm; attempt #$try" + set +e + SRPM=$(rpmbuild -ts "${RELEASE_OPT[@]}" --define "kversion ${KVERSION}.el${EL_VER//./_}.x86_64" --define "dist .el${MAJOR_VER}" scoutfs-kmod-*.tar | awk '{print $2}' ) + set -e + if [ -f "$SRPM" ]; then + echo "SRPM created: $SRPM" + break + fi + try="$((try + 1))" + sleep 5s +done + +if [ -z "$SRPM" ]; then + echo "no srpm found." + exit 1 +fi + +if [ "${MAJOR_VER}" -gt 7 ] ; then + mock_args+=(--dnf) +else + mock_args+=(--yum) +fi + +mock "${mock_args[@]}" --enablerepo epel -r "../scoutfs-build-${EL_VER}.cfg" rebuild "${RELEASE_OPT[@]}" --define "kversion ${KVERSION}.el${EL_VER//./_}.x86_64" --define "dist .el${EL_VER//./_}" --resultdir "./scoutfs_${EL_VER//./_}" "${SRPM}" +if [ "$?" -ne "0" ]; then + exit 1 +fi + +popd + +# make utils rpms +pushd utils +make dist +if [ "$?" -ne "0" ]; then + exit 1 +fi + +SRPM=$(rpmbuild -ts "${RELEASE_OPT[@]}" --define "dist .el${MAJOR_VER}" scoutfs-utils-*.tar | awk '{print $2}') +if [ -z "$SRPM" ]; then + echo "no srpm found." + exit 1 +fi + +mock "${mock_args[@]}" --enablerepo epel -r "../scoutfs-build-${EL_VER}.cfg" rebuild "${RELEASE_OPT[@]}" --define "dist .el${MAJOR_VER}" --resultdir "./scoutfs_${EL_VER//./_}" "${SRPM}" +if [ "$?" -ne "0" ]; then + exit 1 +fi + +popd + +#gpg --export -a 'Versity Software' > RPM-GPG-KEY-scoutfs + +exit 0 + diff --git a/kmod/scoutfs-kmod.spec.in b/kmod/scoutfs-kmod.spec.in index d4085cd9..43c3934d 100644 --- a/kmod/scoutfs-kmod.spec.in +++ b/kmod/scoutfs-kmod.spec.in @@ -7,8 +7,7 @@ # take kernel version or default to uname -r %{!?kversion: %global kversion %(uname -r)} %global kernel_version %{kversion} -% -%define kernel_version_extra %(sed 's/.*-\\([0-9]\\+\\).*/\\1/' <<< "%{kernel_version}") +%define sanitized_kernel_version %(echo %{kernel_version} | tr - _ |sed -e 's/.x86_64//') %if 0%{?el7} %global kernel_source() /usr/src/kernels/%{kernel_version}.$(arch) @@ -19,18 +18,20 @@ %{!?_release: %global _release 0.%{pkg_date}git%{kmod_git_hash}} %if 0%{?el7} -Name: %{kmod_name} +Name: %{kmod_name}-%{sanitized_kernel_version} +Provides: %{kmod_name} %else -Name: kmod-%{kmod_name} +Name: kmod-%{kmod_name}-%{sanitized_kernel_version} +Provides: kmod-%{kmod_name} %endif Summary: %{kmod_name} kernel module Version: %{kmod_version} -Release: %{_release}.%{kernel_version_extra}%{?dist} +Release: %{_release} License: GPLv2 Group: System/Kernel URL: http://scoutfs.org/ -Requires: kernel-core-uname-r >= %{kernel_version} -Requires: kernel-modules-uname-r >= %{kernel_version} +Requires: kernel-core-uname-r = %{kernel_version} +Requires: kernel-modules-uname-r = %{kernel_version} %if 0%{?el7} BuildRequires: %{kernel_module_package_buildreqs}