alpine-chroot-install icon indicating copy to clipboard operation
alpine-chroot-install copied to clipboard

[speedup] Avoid updating package list when no package is to be installed

Open douglas-raillard-arm opened this issue 2 years ago • 2 comments

When no package needs to be installed, we could skip downloading the package list, saving some precious seconds:

    if [ "$ALPINE_PACKAGES" != ' ' ]; then
        apk update
        apk add $ALPINE_PACKAGES
    fi

This is particularly relevant for the following use case:

  1. setup a chroot
  2. unmount fs using the destroy script
  3. Once we have that setup in a cache, we can spin up Alpine "lightweight chroot" almost instantly using:
  4. mount an overlayfs to avoid modifying the underlying cached Alpine root
  5. call alpine-chroot-install in the overlayfs to set it up (bind mounts, sysfs, procfs, /etc/resolv.conf etc). This time, the package list is empty since they are already installed.
  6. Do something in the chroot (e.g. build some code)
  7. Destroy the chroot and unmount/remove the overlayfs upper layer

I am using that system in order to compile in a known environment C sources generated on the fly, so the time it takes to spin up a "fresh" chroot is critical, hence the caching.

douglas-raillard-arm avatar Oct 01 '21 12:10 douglas-raillard-arm

I’ll add it, but please consider that this script has never been designed for this use case. It was meant for CI, nothing else. I’m planning to write another script specifically for the use case you’re mentioning, I need it even for myself.

jirutka avatar Oct 01 '21 14:10 jirutka

Interesting, do you plan on adding it to the same repo or will it land somewhere else ? I would definitely check it out when it comes to life. This sort of tooling is partly why I chose Alpine for that lean build "container" (and also because of static linking).

Thanks a lot

douglas-raillard-arm avatar Oct 01 '21 16:10 douglas-raillard-arm