From: Michael Tremer Date: Wed, 24 Mar 2021 10:25:07 +0000 (+0000) Subject: builder: Automatically create/restore snapshots X-Git-Tag: 0.9.28~1285^2~481 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6a160d3087b97f7f7e77d45db6a5b94b1b516006;p=pakfire.git builder: Automatically create/restore snapshots Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/builder.py b/src/pakfire/builder.py index 0d7fe0f44..e90988c8d 100644 --- a/src/pakfire/builder.py +++ b/src/pakfire/builder.py @@ -49,6 +49,18 @@ BUILD_LOG_HEADER = """ """ +BUILD_PACKAGES = [ + "@Build", + "ccache", + "pakfire-build", + "/bin/bash", + + # Handy shell tools + "elinks", + "less", + "vim", +] + BUILD_SCRIPT = """#!/bin/bash --login set -e @@ -168,6 +180,9 @@ class BuilderContext(object): # Get a reference to the logger self.log = self.builder.log + # Setup the environment + self._setup() + @property def environ(self): # Build a minimal environment for executing, but try to inherit TERM and LANG @@ -192,6 +207,24 @@ class BuilderContext(object): return env + def _setup(self): + """ + Sets up the environment by installing some basic packages + """ + # XXX this needs to be unique for each distribution + snapshot_path = "/tmp/pakfire-snapshot.tar.zst" + + # Restore the snapshot if available + try: + self.pakfire.restore_snapshot(snapshot_path) + except FileNotFoundError: + pass + + # Install any updates and essential packages + # If there have been updates, or on a fresh install, re-create the snapshot + if self._install(BUILD_PACKAGES): + self.pakfire.create_snapshot(snapshot_path) + def _install(self, packages): self.log.debug(_("Installing packages in build environment:")) for package in packages: @@ -202,6 +235,9 @@ class BuilderContext(object): # Install all required packages transaction = p.install(packages) + # Return how many packages were installed/changed + ret = len(transaction) + # Dump transaction to log t = transaction.dump() self.log.info(t) @@ -212,16 +248,9 @@ class BuilderContext(object): # Run the transaction transaction.run() - def build(self, path, shell=True): - # Install build environment - packages = [ - "@Build", - ] - - # If we have ccache enabled, we need to install it, too - if self.builder.settings.get("enable_ccache"): - packages.append("ccache") + return ret + def build(self, path, shell=True): # Open the package archive archive = _pakfire.Archive(self.pakfire, path) @@ -230,10 +259,10 @@ class BuilderContext(object): requires = archive.get("dependencies", "requires") if requires: - packages += requires.splitlines() + packages = requires.splitlines() - # Setup the environment including any build dependencies - self._install(packages) + # Setup the environment including any build dependencies + self._install(packages) # Extract the source archive (if we have one) if archive: @@ -284,24 +313,19 @@ class BuilderContext(object): archive = _pakfire.Archive(self.pakfire, path) archives.append(archive) - # Collect packages to install - packages = [] - - # Install our standard shell packages - packages += SHELL_PACKAGES - # Install any packages the user requested - if install: - packages += install + if not install: + install = [] # Install all build requirements for archives for archive in archives: requires = archive.get("dependencies.requires") if requires: - packages += requires.splitlines() + install += requires.splitlines() # Install all required packages - self._install(packages) + if install: + self._install(install) # Extract archives for archive in archives: diff --git a/src/pakfire/constants.py b/src/pakfire/constants.py index ae75c74d7..368ce55cc 100644 --- a/src/pakfire/constants.py +++ b/src/pakfire/constants.py @@ -67,8 +67,6 @@ DATABASE_FORMATS_SUPPORTED = [0, 1, 2, 3, 4, 5, 6, 7] PACKAGE_FILENAME_FMT = "%(name)s-%(version)s-%(release)s.%(arch)s.%(ext)s" # A script that is called, when a user is dropped to a chroot shell. -SHELL_SCRIPT = "/usr/lib/pakfire/chroot-shell" -SHELL_PACKAGES = ["elinks", "less", "vim", SHELL_SCRIPT,] BUILD_ROOT = "/var/lib/pakfire/build" SOURCE_CACHE_DIR = os.path.join(CACHE_DIR, "sources")