Skip to content

Commit

Permalink
oci-as-buildroot
Browse files Browse the repository at this point in the history
  • Loading branch information
praiskup committed Oct 22, 2024
1 parent 15c2b9b commit a55ac9d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
4 changes: 3 additions & 1 deletion mock/py/mockbuild/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
'ccache', 'selinux', 'package_state', 'chroot_scan',
'lvm_root', 'compress_logs', 'sign', 'pm_request',
'hw_info', 'procenv', 'showrc', 'rpkg_preprocessor',
'rpmautospec', 'buildroot_lock']
'rpmautospec', 'buildroot_lock', 'oci_as_buildroot']

def nspawn_supported():
"""Detect some situations where the systemd-nspawn chroot code won't work"""
Expand Down Expand Up @@ -234,6 +234,8 @@ def setup_default_config_opts():
'process-distgit',
]
},
'oci_as_buildroot_enable': True,
'oci_as_buildroot_opts': {},
}

config_opts['environment'] = {
Expand Down
39 changes: 39 additions & 0 deletions mock/py/mockbuild/plugins/oci_as_buildroot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""
Generate OCI from prepared build chroot.
Use given OCI image as build chroot (TODO).
"""

from mockbuild.util import do

requires_api_version = "1.1"


def init(plugins, conf, buildroot):
""" The obligatory plugin entry point """
OCIAsBuildroot(plugins, conf, buildroot)


class OCIAsBuildroot:
"""
OCIAsBuildroot plugin (class).
"""
def __init__(self, plugins, conf, buildroot):
self.buildroot = buildroot
self.state = buildroot.state
self.conf = conf
plugins.add_hook("postdeps", self.produce_buildroot_image)

def _produce_image_as_root(self):

name = "mock-container-foo"
tarball = "/tmp/mock.tar"
chroot = self.buildroot.make_chroot_path()
do(["buildah", "from", "--name", name, "scratch"])
do(["buildah", "add", name, chroot, "/"])
do(["buildah", "commit", "--format", "oci", name,
"oci-archive:" + tarball])

def produce_buildroot_image(self):
""" Generate OCI image from buildroot using Buildah """
with self.buildroot.uid_manager.elevated_privileges():
self._produce_image_as_root()

0 comments on commit a55ac9d

Please sign in to comment.