alpinelinux / alpine-chroot-install

Install Alpine Linux in chroot with a breeze. Build ARM on Travis CI or any other x86_64 CI.
MIT License
290 stars 59 forks source link

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

Open douglas-raillard-arm opened 3 years ago

douglas-raillard-arm commented 3 years ago

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.

jirutka commented 3 years ago

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.

douglas-raillard-arm commented 3 years ago

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