Install abuild via Docker
Explore the process of setting up abuild within an Alpine Linux Docker container. This lesson guides you through installing required tools, configuring build dependencies, generating cryptographic keys for signing packages, and preparing your environment for building Alpine Linux packages securely.
We'll cover the following...
Preface
Now that we have learned the basics of Alpine Linux, we can start practicing how to build packages.
Setting up a Docker container
The easiest way to start using Alpine Linux is through Docker. We can use Docker via the terminal widgets that are built into this course. We can run any command we could run in a usual Alpine Linux Docker container with these widgets. Let’s try running cat /etc/os-release in the terminal below to see what Alpine Linux release version we’re using!
Try running the command in the terminal below:
Running Alpine Linux
The terminal widget above runs the Alpine Linux Docker container for us. If we wanted to start a Docker container locally on our computer later on, we could use the command below. This would start an ash shell in an Alpine Linux container:
Let’s go over the individual parts of the command above:
-
runmeans that the specified container image (alpine:3.15) should be started. -
--interactivemeans that we want to run an interactive session in this container where we can enter commands in a shell. -
--ttyopens a terminal in the container upon start. Since--interactiveand--ttyare usually used together, the short form-itis used to enable both of these options in the following lessons. -
--namesets the name of the container so we can interact with the container later on via its name. -
alpine:3.15This specifies the container image to run. In this case, we want to run Alpine Linux with the release version3.15.
After the program has been executed, we are greeted by a shell in the container. We can run commands on this shell:
This produces the following output:
We can exit the container by typing exit into the terminal.
Setting up abuild
Now that we have done the initial setup, we can reenter our Alpine Linux container by typing docker start -ai educative-alpine in our terminal, or we can use the terminal widget below. This will resume the previous session in this container. We specify -a to connect the container’s output to our terminal (so we can see what output the commands we’ve entered produce) and -i in order for the container to receive the input we type into our terminal.
We can start installing abuild afterward because first, we have to install alpine-sdk. The latter package installs all build dependencies, like a C compiler, that are required for almost all packages:
Afterward, we can set up the cache directory for distfiles (files that are downloaded during the package build):
Then, we can generate our private and public keys that are used to cryptographically sign the packages we build to ensure integrity:
Let’s go over the arguments to abuild-keygen again.
-a: Automatically set the generated key as our default signing key.-i: Automatically install the public key.-n: Run in noninteractive mode, which automatically uses the defaults ofabuild.
As noted in the output, the public key has been written to /etc/apk/keys. This is, as the name suggests, supposed to be available to everyone that uses our repository because apk uses this key to verify packages after downloading them. Since abuild-keygen already installed the public key in the right directory for our installation (because we specified -i), we don’t have to worry about this for now. We’ll talk about distributing the packages in a later lesson. We can check how the format of the RSA-key looks:
A private key has also been generated for us by abuild-keygen. We can use it for signing the packages we build. This key has to be kept private since it would allow others to impersonate our package builds if they had our private key.
Try following along the setup process in the terminal below:
The first command adds the required packages, which are as follows:
abuildprovides theabuild-keygencommand to generate the keypair.alpine-sdkis a required dependency for usingabuild.sudois used byabuildto install the keypair.
Afterward, we create the distfiles cache with mkdir, and finally, we generate our keypair.
Now that we have set up abuild, we can go ahead and build our first APKBUILD.