alpine-chroot-install
alpine-chroot-install copied to clipboard
[speedup] Avoid updating package list when no package is to be installed
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:
- setup a chroot
- unmount fs using the
destroy
script - Once we have that setup in a cache, we can spin up Alpine "lightweight chroot" almost instantly using:
- mount an overlayfs to avoid modifying the underlying cached Alpine root
- 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.
- Do something in the chroot (e.g. build some code)
- 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.
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.
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