From b74cd7f7c4c5600f10d43c1f235b18d101af532f Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Wed, 21 Jun 2023 15:48:52 +0200 Subject: [PATCH] Don't update bootstrap from image, if possible There's a new option config_opts['bootstrap_image_ready'] which, if set, causes that Mock doesn't try to install any tooling into it (silently expecting that 'dnf' and 'dnf builddep' works inside). Turns out that e.g. the ubi8 and ubi9 images have the 'builddep' command installed by default, therefore we can turn this option ON by default. Fixes: #1088 --- .../etc/mock/templates/rhel-8.tpl | 1 + .../etc/mock/templates/rhel-9.tpl | 1 + mock/py/mockbuild/buildroot.py | 43 +++++++++++++++++++ mock/py/mockbuild/config.py | 1 + 4 files changed, 46 insertions(+) diff --git a/mock-core-configs/etc/mock/templates/rhel-8.tpl b/mock-core-configs/etc/mock/templates/rhel-8.tpl index 2460c4eb3..2f894d981 100644 --- a/mock-core-configs/etc/mock/templates/rhel-8.tpl +++ b/mock-core-configs/etc/mock/templates/rhel-8.tpl @@ -4,6 +4,7 @@ config_opts['extra_chroot_dirs'] = [ '/run/lock', ] config_opts['releasever'] = '8' config_opts['package_manager'] = 'dnf' config_opts['bootstrap_image'] = 'registry.access.redhat.com/ubi8/ubi' +config_opts['bootstrap_image_ready'] = True config_opts['description'] = 'RHEL 8' config_opts['dnf_install_command'] += ' subscription-manager' diff --git a/mock-core-configs/etc/mock/templates/rhel-9.tpl b/mock-core-configs/etc/mock/templates/rhel-9.tpl index 74afbf23c..7b833b18e 100644 --- a/mock-core-configs/etc/mock/templates/rhel-9.tpl +++ b/mock-core-configs/etc/mock/templates/rhel-9.tpl @@ -4,6 +4,7 @@ config_opts['dist'] = 'el{{ releasever }}' # only useful for --resultdir variab config_opts['extra_chroot_dirs'] = [ '/run/lock', ] config_opts['package_manager'] = 'dnf' config_opts['bootstrap_image'] = 'registry.access.redhat.com/ubi{{ releasever }}/ubi' +config_opts['bootstrap_image_ready'] = True config_opts['description'] = 'RHEL {{ releasever }}' config_opts['dnf_install_command'] += ' subscription-manager' diff --git a/mock/py/mockbuild/buildroot.py b/mock/py/mockbuild/buildroot.py index b3801be40..af467ee1d 100644 --- a/mock/py/mockbuild/buildroot.py +++ b/mock/py/mockbuild/buildroot.py @@ -26,6 +26,9 @@ from .shadow_utils import ShadowUtils +# pylint: disable=too-many-lines + + def noop_in_bootstrap(f): # pylint: disable=inconsistent-return-statements def wrapper(self, *args, **kwargs): @@ -422,6 +425,9 @@ def _init_pkg_management(self): # The desired package manager. pm = self.config['package_manager'] + if self.bootstrap_image_is_ready: + return + if self.is_bootstrap: update_state = f'installing {pm} tooling' cmd = self.config.get(f"{pm}_install_command") @@ -931,6 +937,43 @@ def delete(self): def uses_bootstrap_image(self): return self.is_bootstrap and self.use_bootstrap_image + @property + def bootstrap_image_is_ready(self): + """ + True if bootstrap image is in use, bootstrap_image_ready==True, and no + config_opts field is set that would invalidate the bootstrap + "readiness" state. + """ + if not self.uses_bootstrap_image: + return False + + # TODO(praiskup): Can we have heuristic for checking if extracted + # buildroot is ready? + + # All the options checked here were copied from the corresponding + # `bootstrap_` prefixed config option. + if not self.config['image_ready']: + self.root_log.info("Bootstrap image not marked ready") + return False + + # Per configuration, we think that image is ready-made (e.g. ubi8 images + # have the 'dnf builddep' command available by default). But there + # still might be reasons to do some updates. + for check_option in [ + "module_enable", "module_install", "module_setup_commands", + "chroot_additional_packages" + ]: + if self.config.get(check_option): + self.root_log.info( + f"Package management in bootstrap (from image) is going to " + f"be updated because config_opts['{check_option}'] is set." + ) + return False + + self.root_log.info("Not updating bootstrap chroot, " + "bootstrap_image_ready=True") + return True + @traceLog() def install_as_root(self, *deps): """ Becomes root user and calls self.install() """ diff --git a/mock/py/mockbuild/config.py b/mock/py/mockbuild/config.py index f351ac640..420d06f60 100644 --- a/mock/py/mockbuild/config.py +++ b/mock/py/mockbuild/config.py @@ -83,6 +83,7 @@ def setup_default_config_opts(): config_opts['use_bootstrap'] = True config_opts['use_bootstrap_image'] = False config_opts['bootstrap_image'] = 'fedora:latest' + config_opts['bootstrap_image_ready'] = False config_opts['internal_dev_setup'] = True