From 180a58c0f1d834582450837dbe810529496c4200 Mon Sep 17 00:00:00 2001 From: Patryk Matuszak Date: Fri, 14 Nov 2025 15:23:57 +0100 Subject: [PATCH] Modify microshift.spec mid build --- packaging/microshift-builder.Containerfile | 16 +++- src/image/modify-spec.py | 86 ++++++++++++++++++++++ src/image/postbuild.sh | 9 --- 3 files changed, 100 insertions(+), 11 deletions(-) create mode 100755 src/image/modify-spec.py diff --git a/packaging/microshift-builder.Containerfile b/packaging/microshift-builder.Containerfile index 26345b10..6e99b1cc 100644 --- a/packaging/microshift-builder.Containerfile +++ b/packaging/microshift-builder.Containerfile @@ -12,6 +12,7 @@ ENV HOME=/home/microshift ARG BUILDER_RPM_REPO_PATH=${HOME}/microshift/_output/rpmbuild/RPMS ARG USHIFT_PREBUILD_SCRIPT=/tmp/prebuild.sh ARG USHIFT_POSTBUILD_SCRIPT=/tmp/postbuild.sh +ARG USHIFT_MODIFY_SPEC_SCRIPT=/tmp/modify-spec.py # Verify mandatory build arguments RUN if [ -z "${OKD_VERSION_TAG}" ] ; then \ @@ -24,8 +25,11 @@ RUN if [ -z "${OKD_VERSION_TAG}" ] ; then \ RUN useradd -m -s /bin/bash "${USER}" && \ echo "${USER} ALL=(ALL) NOPASSWD: ALL" > "/etc/sudoers.d/${USER}" && \ chmod 0640 /etc/shadow && \ - dnf install -y git && \ - dnf clean all + dnf install -y \ + --setopt=install_weak_deps=False \ + git rpm-build jq python3-pip createrepo && \ + dnf clean all && \ + pip install specfile # Set the user and work directory USER ${USER}:${USER} @@ -36,10 +40,18 @@ RUN git clone --branch "${USHIFT_BRANCH}" --single-branch "${USHIFT_GIT_URL}" "$ echo '{"auths":{"fake":{"auth":"aWQ6cGFzcwo="}}}' > /tmp/.pull-secret && \ "${HOME}/microshift/scripts/devenv-builder/configure-vm.sh" --no-build --no-set-release-version --skip-dnf-update /tmp/.pull-secret +WORKDIR ${HOME}/microshift/ + # Preparing the build scripts COPY --chmod=755 ./src/image/prebuild.sh ${USHIFT_PREBUILD_SCRIPT} RUN "${USHIFT_PREBUILD_SCRIPT}" --replace "${OKD_RELEASE_IMAGE}" "${OKD_VERSION_TAG}" +# Modify the microshift.spec to remove packages not yet supported by the upstream. +COPY --chmod=755 ./src/image/modify-spec.py ${USHIFT_MODIFY_SPEC_SCRIPT} +# Disable the RPM and SRPM checks in the make-rpm.sh script. +RUN sed -i -e 's,CHECK_RPMS="y",,g' -e 's,CHECK_SRPMS="y",,g' ./packaging/rpm/make-rpm.sh && \ + ${USHIFT_MODIFY_SPEC_SCRIPT} + # Building all MicroShift downstream RPMs and SRPMs # hadolint ignore=DL3059 RUN MICROSHIFT_VARIANT="community" make -C "${HOME}/microshift" rpm srpm diff --git a/src/image/modify-spec.py b/src/image/modify-spec.py new file mode 100755 index 00000000..96e64e65 --- /dev/null +++ b/src/image/modify-spec.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python + +""" +Following script modifies downstream microshift.spec to remove packages not yet supported by the upstream. + +When some package will be supported by the upstream, remove the package name from the pkgs_to_remove list and right keywords from the install_keywords_to_remove list. +""" + +import specfile +from itertools import product + +# Subpackages to remove +pkgs_to_remove = [ + 'multus', + 'low-latency', + 'gateway-api', + 'ai-model-serving', + 'cert-manager', + 'observability', +] + +# Sections to remove for the subpackages +sections_to_remove = [ + 'package', + 'description', + 'files', + 'preun', + 'post', +] + +# Product of pkgs_to_remove and sections_to_remove, and the '-release-info' suffix. +# Result is a list of strings like: 'package multus', 'description multus', 'files multus-release-info', etc. +full_sections_to_remove = [ f"{p[0]} {p[1]}{p[2]}" for p in product(sections_to_remove, pkgs_to_remove, ["", "-release-info"]) ] + +# Words that identify lines to remove from the install section. +install_keywords_to_remove = [ + 'multus', + 'low-latency', + 'lib/tuned', + '05-high-performance-runtime.conf', + 'microshift-baseline', + 'microshift-tuned', + 'gateway-api', + 'ai-model-serving', + 'cert-manager', + 'observability', +] + +s = specfile.Specfile( + './packaging/rpm/microshift.spec', + # Dummy macro values - they are referenced in the spec file but not provided by default, only added when running make-rpm.sh. + # Without these, specfile cannot be parsed because of the recursive references (because microshift.spec actually redefines macros defined by default...) + macros=[('release', '1'), ('version', '4.0.0'), ('commit', 'x'), ('embedded_git_tag', 'tag'), ('embedded_git_tree_state', 'clean')]) + +with s.sections() as sections: + for id in full_sections_to_remove: + try: + sec = sections.get(id) + sections.remove(sec) + print(f"Removing section: '%{id}'") + except ValueError as e: + # Ignore non-existent sections + pass + + i = sections.install + new_install = [] + nl_present = False + for line in i: + # If the line contains any of the keywords - remove the line (= don't append to new_install) + if any(substring in line for substring in install_keywords_to_remove): + print(f"Removing line: '{line}'") + else: + if line == "": + # Skip extraneous newlines for aesthetic reasons + if nl_present: + continue + else: + nl_present = True + new_install.append(line) + else: + nl_present = False + new_install.append(line) + i.clear() + i.extend(new_install) + +s.save() diff --git a/src/image/postbuild.sh b/src/image/postbuild.sh index d75324cb..64940a7d 100644 --- a/src/image/postbuild.sh +++ b/src/image/postbuild.sh @@ -5,15 +5,6 @@ set -x # Variables BUILDER_RPM_REPO_PATH="$1" -# Delete unsupported RPMs, which are built unconditionally. -# To add support for an RPM, undo the file removal and add a presubmit test for it. -rm -f "${BUILDER_RPM_REPO_PATH}"/*/microshift-ai-model-serving*.rpm -rm -f "${BUILDER_RPM_REPO_PATH}"/*/microshift-cert-manager*.rpm -rm -f "${BUILDER_RPM_REPO_PATH}"/*/microshift-gateway-api*.rpm -rm -f "${BUILDER_RPM_REPO_PATH}"/*/microshift-low-latency*.rpm -rm -f "${BUILDER_RPM_REPO_PATH}"/*/microshift-multus*.rpm -rm -f "${BUILDER_RPM_REPO_PATH}"/*/microshift-observability*.rpm - # Create a local RPM repository and add SRPMs on top of it mkdir -p "${BUILDER_RPM_REPO_PATH}/srpms" createrepo -v "${BUILDER_RPM_REPO_PATH}"