We write and build our PKGBUILD
files in our local machine, but we need to make sure our build script is portable and up to date with the required dependencies.
If you've built a CI before, you already know that Docker is a de facto solution for this. You should create a container, install the dependencies to build Arch Linux package, and then build your PKGBUILD to check the success result.
Creating the container
First, we should install the docker package and start its service:
sudo pacman -S docker
sudo systemctl start docker.service
Then, start an interactive container using the Arch Linux image as base:
sudo docker run -it archlinux bash
Preparing the container
We should add the base-devel
package group to our container - these packages are required to build packages ourselves. The Arch Linux team is working in a new docker image archlinux:devel
with this package group pre-installed.
And, Git if we want to test a PKGBUILD
hosted in the AUR repository.
pacman -Sy --noconfirm base-devel git
💡 Tip: Maybe you need to check the /etc/pacman.d/mirrorlist
file to get a good bandwidth based on your geolocation.
Add a non-root user
For security reasons, makepkg
can't run as root
, but we need to add a user with sudo to build the package.
useradd builduser -m # Create the builduser
passwd -d builduser # Delete the buildusers password
printf 'builduser ALL=(ALL) ALL\n' | tee -a /etc/sudoers # Allow the builduser passwordless sudo
Now, change the user:
su builduser && cd
Cloning the AUR package
We can clone the AUR package without using an AUR helper, like yay
. We'll use the .Net Core app we visited in the previous post.
git clone https://aur.archlinux.org/taskcore.git
Build the package
And now we can build and install our package
makepkg -si --noconfirm
Then, clean the orphan packages that we don't need on runtime:
pacman -Rns $(pacman -Qtdq)
Automate the build process
We can create a Dockerfile
to run the build steps without an interactive terminal.
FROM archlinux
RUN pacman -Sy --noconfirm base-devel git
ARG AUR_PACKAGE=taskcore
RUN useradd builduser -m \
&& passwd -d builduser \
&& cd /home/builduser \
&& git clone "https://aur.archlinux.org/$AUR_PACKAGE.git" target \
&& chown builduser -R target \
&& (printf 'builduser ALL=(ALL) ALL\n' | tee -a /etc/sudoers) \
&& sudo -u builduser bash -c 'cd ~/target && makepkg -si --noconfirm' \
&& pacman -Rns $(pacman -Qtdq)
WORKDIR /home/builduser/target
CMD ["bash"]
We can build other packages using the --build-arg
argument:
sudo docker build --build-arg AUR_PACKAGE=git-delta -t git-delta .
Run the package!
Don't forget to run the package to check the runtime dependencies.
docker run -it taskcore
taskcore ls
New base-devel image! (Update 2020-11-06)
The ticket was closed and the new archlinux:base-devel
image is available, with a current size of 700MB vs 467MB for archlinux:latest
(a.k.a. archlinux:base
).
Top comments (0)