Skip to content

Commit

Permalink
Use buildroot from container image
Browse files Browse the repository at this point in the history
For now as:
--config-opts buildroot_image=registry.fedoraproject.org/fedora:41

Fixes: rpm-software-management#1159
  • Loading branch information
praiskup committed Oct 29, 2024
1 parent d482b17 commit a78ea26
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
25 changes: 19 additions & 6 deletions mock/py/mockbuild/buildroot.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,18 @@ def __init__(self, config, uid_manager, state, plugins, bootstrap_buildroot=None
self.env.update(proxy_env)
os.environ.update(proxy_env)

self.use_chroot_image = self.config['use_bootstrap_image']
self.chroot_image = self.config['bootstrap_image']
if is_bootstrap:
self.use_chroot_image = self.config['use_bootstrap_image']
self.chroot_image = self.config['bootstrap_image']
self.image_skip_pull = self.config["bootstrap_image_skip_pull"]
self.image_assert_digest = self.config.get("bootstrap_image_assert_digest", None)
self.image_keep_getting = self.config["bootstrap_image_keep_getting"]
else:
self.use_chroot_image = self.config["use_buildroot_image"]
self.chroot_image = self.config["buildroot_image"]
self.image_skip_pull = self.config["buildroot_image_skip_pull"]
self.image_assert_digest = self.config.get("buildroot_image_assert_digest", None)
self.image_keep_getting = self.config["buildroot_image_keep_getting"]

self.pkg_manager = None
self.mounts = mounts.Mounts(self)
Expand Down Expand Up @@ -239,7 +249,10 @@ def _init_locked(self):

@traceLog()
def _load_from_container_image(self):
if not self.uses_bootstrap_image or self.chroot_was_initialized:
if self.chroot_was_initialized:
return

if not self.use_chroot_image:
return

if util.mock_host_environment_type() == "docker":
Expand Down Expand Up @@ -269,15 +282,15 @@ def _fallback(message):
podman = Podman(self, self.chroot_image)

with _fallback("Can't initialize from container image"):
if not self.config["image_skip_pull"]:
podman.retry_image_pull(self.config["image_keep_getting"])
if not self.image_skip_pull:
podman.retry_image_pull(self.image_keep_getting)
else:
podman.read_image_id()
getLog().info("Using local image %s (%s)",
self.chroot_image, podman.image_id)
podman.tag_image()

digest_expected = self.config.get("image_assert_digest", None)
digest_expected = self.image_assert_digest
if digest_expected:
getLog().info("Checking image digest: %s",
digest_expected)
Expand Down
11 changes: 11 additions & 0 deletions mock/py/mockbuild/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ def setup_default_config_opts():
config_opts['bootstrap_image_keep_getting'] = 120
config_opts['bootstrap_image_assert_digest'] = None

config_opts['use_buildroot_image'] = False
config_opts['buildroot_image'] = None
config_opts['buildroot_image_skip_pull'] = True
config_opts['buildroot_image_ready'] = False
config_opts['buildroot_image_fallback'] = True
config_opts['buildroot_image_keep_getting'] = 120
config_opts['buildroot_image_assert_digest'] = None

config_opts['internal_dev_setup'] = True

# cleanup_on_* only take effect for separate --resultdir
Expand Down Expand Up @@ -672,6 +680,9 @@ def set_config_opts_per_cmdline(config_opts, options, args):
if config_opts["calculatedeps"]:
config_opts["plugin_conf"]["buildroot_lock_enable"] = True

if config_opts["buildroot_image"]:
config_opts["use_buildroot_image"] = True

def check_config(config_opts):
if 'root' not in config_opts:
raise exception.ConfigError("Error in configuration "
Expand Down

0 comments on commit a78ea26

Please sign in to comment.