From 03e2b52dad1660ef758db7bab3a888f546e5cedb Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Wed, 23 Nov 2022 15:29:54 +0000 Subject: [PATCH] WIP: Use host system OSTree repo as local cache When running the image builder on Endless OS, there is a high chance that the host system will be running a similar, if not identical, OSTree commit to the one being built into the image. In my case, I run master and update essentially every morning, so running the image builder with its default arguments will use the same OSTree as is booted. `ostree pull` supports a `--localcache-repo PATH` argument: > Like git's clone --reference. Reuse the provided OSTree repo as a > local object cache when doing HTTP fetches. In this patch, we bind-mount the host's /ostree/repo into the buildroot, if it exists. The bind-mount is made read-only to reduce the risk that a bug in the image builder will mess up the host system. --- run-build | 7 +++++-- stages/eib_ostree | 7 +++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/run-build b/run-build index e7379659..19153955 100755 --- a/run-build +++ b/run-build @@ -77,6 +77,7 @@ class ImageBuildRoot(object): # Optional mounts dependent on existence on the host optional_mounts = [ config['build']['sysconfdir'], + '/ostree/repo', ] # Include local settings directory if provided @@ -179,9 +180,9 @@ class ImageBuildRoot(object): # Really mount the directories for path in to_mount: - self.mount(path) + self.mount(path, read_only=(path == '/ostree/repo')) - def mount(self, path, target=None): + def mount(self, path, target=None, read_only=False): """Bind mount path in the build directory""" if not os.path.isabs(path): raise eib.ImageBuildError('Buildroot mount path', path, @@ -206,6 +207,8 @@ class ImageBuildRoot(object): with open(mount_path, 'w'): pass subprocess.check_call(['mount', '--bind', path, mount_path]) + if read_only: + subprocess.check_call(['mount', '-o', 'remount,bind,ro', path, mount_path]) def __enter__(self): return self diff --git a/stages/eib_ostree b/stages/eib_ostree index c859323c..1bbae8e7 100755 --- a/stages/eib_ostree +++ b/stages/eib_ostree @@ -27,7 +27,14 @@ ostree --repo="${EIB_OSTREE_REPODIR}" remote delete --if-exists \ ostree --repo="${EIB_OSTREE_REPODIR}" remote add \ --set=gpg-verify-summary=true \ ${EIB_OSTREE_REMOTE} ${BUILD_OSTREE_URL} ${EIB_OSTREE_REF} +if [ -d /ostree/repo ] +then + extra_pull_args=(--localcache-repo /ostree/repo) +else + extra_pull_args=() +fi eib_retry ostree --repo="${EIB_OSTREE_REPODIR}" pull \ + ${extra_pull_args[@]} \ ${EIB_OSTREE_REMOTE} ${EIB_OSTREE_REF} # Recreate the ref locally so that the deploy can pull from it