Maintaining and Building Alpine Packages From Arch Linux

Alpine packaging tooling are now available in the Arch Linux [extra] repository!

I recently added the abuild and atools Alpine packaging tooling to the Arch Linux [extra] repository.

Thanks to that, these tools can now be used to maintain and build Alpine packages (in a clean chroot) from an Arch Linux system, without requiring to rely on a separate Alpine installation, such as a container or a VM.
By enabling the Alpine packaging workflow directly from an Arch Linux system, this streamlines the process of maintaining Alpine packages for Arch users that also contribute to Alpine Linux (like I do).

Of course, due to technical differences between Alpine and Arch Linux (e.g. in terms of package manager, init system and C library implementation), building Alpine packages on an Arch system outside of an Alpine clean chroot is not possible. As such, when building Alpine packages on an Arch system, only abuild rootbld is relevant to use.

Environment setup to perform Alpine packaging from Arch Linux

Install the abuild and atools packages:

sudo pacman -S abuild atools

To be able to build Alpine packages in a clean chroot with abuild rootbld, you need to generate a public / private rsa key pair with the abuild-keygen tool and add your user to the abuild group (which is created when installing the abuild package):

abuild-keygen -a -i
sudo usermod -aG abuild "username" # Requires a logout / login to take effect

One can optionally edit the /etc/abuild.conf configuration file to their liking and requirements. For instance, the paths used to store downloaded sources (/var/cache/distfiles by default) and built packages (~/packages by default) can be customized by modifying the SRCDEST and REPODEST parameters respectively in that configuration file.

See the Arch wiki abuild page for more details.

Basic Alpine packaging workflow from Arch Linux

With the above setup, I’m able to perform my usual basic Alpine packaging workflow directly from my Arch Linux system:

newapkbuild "package_name" && cd "package_name" # Create a new port for a package and `cd` into it
vim APKBUILD # Edit the APKBUILD
apkbuild-lint APKBUILD # Run the apkbuild linter
apkbuild-fixer APKBUILD # Attempt to automatically fix potential warnings raised by `apkbuild-lint`
abuild checksum # Generate / upgrade checksum for the source(s) contained in the APKBUILD source array
abuild rootbld # Build the package in an Alpine clean chroot

I was initially using an Alpine container to access the necessary tooling to perform my Alpine packaging workflow, but this method had some flaws. Indeed, in addition to the fact that working from a container is not as comfortable as working from my actual system; building packages in a clean chroot using abuild rootbld inside a Docker container eventually requires some additional setup, and fakeroot (used during the packages build process) currently has some issues when used inside containers which, for instance, cause it to be extremely slow (see this and this bug reports).

Being able to run such Alpine packaging tooling directly from my Arch Linux system streamlines the packaging workflow I use to maintain my Alpine packages (and hopefully the one of other Arch users & Alpine contributors too ✌️).