forked from rpm-software-management/mock
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes: rpm-software-management#1482
- Loading branch information
Showing
3 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
""" | ||
Generate OCI from prepared build chroot. | ||
Use given OCI image as build chroot (TODO). | ||
""" | ||
|
||
import os | ||
import mockbuild.util | ||
from mockbuild.trace_decorator import getLog | ||
|
||
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 do(self, cmd): | ||
""" Execute command on host (as root) """ | ||
getLog().info("Executing %s", ' '.join(cmd)) | ||
mockbuild.util.do(cmd) | ||
|
||
def _produce_image_as_root(self): | ||
name = f"mock-container-{self.buildroot.config['root']}" | ||
# TODO: chain build produces multiple buildroots | ||
tarball = os.path.join(self.buildroot.resultdir, "buildroot-oci.tar") | ||
chroot = self.buildroot.make_chroot_path() | ||
self.do(["buildah", "from", "--name", name, "scratch"]) | ||
self.do(["buildah", "add", name, chroot, "/"]) | ||
self.do(["buildah", "commit", "--format", "oci", name, | ||
"oci-archive:" + tarball]) | ||
self.do(["buildah", "rm", name]) | ||
|
||
def produce_buildroot_image(self): | ||
""" Generate OCI image from buildroot using Buildah """ | ||
try: | ||
self.state.start("producing buildroot as OCI image") | ||
with self.buildroot.uid_manager.elevated_privileges(): | ||
self._produce_image_as_root() | ||
finally: | ||
self.state.finish("producing buildroot as OCI image") |