From 5d286e5a324d267c52b6a84c705d3e24ddd3946e Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Wed, 23 Nov 2022 15:29:54 +0000 Subject: [PATCH] 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. On my developer system & internet connection (80 Mbps according to fast.com), in the case where my system repo has the latest commit but the eos-image-builder cache repo does not, the pull takes 15 seconds with this patch. Without it, the pull takes, let's say, substantially longer. I gave up after 10 minutes, after which time 26% of objects have been pulled, topping out at around 900 kB/s. --- run-build | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/run-build b/run-build index eb763a2e..28a54eeb 100755 --- a/run-build +++ b/run-build @@ -95,11 +95,23 @@ class ImageBuildRoot(object): repo_path = config['ostree']['repodir'] remote = config['ostree']['remote'] ref = config['ostree']['ref'] + + # If we are on an OSTree system, use the system repo as an additional cache. + # In the case of an Endless OS developer system booted into the same or similar + # ref as we are building an image of, this saves a full over the network. In + # other cases it is harmless. + system_ostree_repo = '/ostree/repo' + if False and os.path.isdir(system_ostree_repo): + extra_pull_args = ['--localcache-repo', system_ostree_repo] + else: + extra_pull_args = [] + log.info(f'Pulling OSTree ref {remote}:{ref}') eib.retry(subprocess.check_call, [ 'ostree', f'--repo={repo_path}', 'pull', + *extra_pull_args, remote, ref, ])