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.

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.
  • Loading branch information
wjt committed Nov 10, 2023
1 parent 25d554e commit 1f522f2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 5 additions & 2 deletions run-build
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions stages/eib_ostree
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ ostree --repo="${EIB_OSTREE_REPODIR}" remote delete --if-exists \
ostree --repo="${EIB_OSTREE_REPODIR}" remote add \
--set=gpg-verify-summary="${gpg_verify_summary}" \
${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
Expand Down

0 comments on commit 1f522f2

Please sign in to comment.