Skip to content

Commit

Permalink
Use host system OSTree repo as local cache
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wjt committed Nov 15, 2023
1 parent abca960 commit 16f1652
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions run-build
Original file line number Diff line number Diff line change
Expand Up @@ -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 pulling 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,
])
Expand Down

0 comments on commit 16f1652

Please sign in to comment.