Building multi-arch images using self-hosted runners on GitHub Actions
GitHub Actions is a continuous integration and continuous delivery (CI/CD) platform that allows you to automate your build, test, and deployment pipeline. You can create workflows that build and test every pull request to your repository, or deploy merged pull requests to production. It goes beyond just DevOps and lets you run workflows when other events happen in your repository.
GitHub provides Ubuntu Linux, Microsoft Windows, and macOS runners to run your workflows; each workflow run executes in a fresh, newly-provisioned virtual machine. If you need a different operating system or require a specific hardware configuration, you can host your own runners.
In this tutorial, we will see how to build multi-arch images by using self-hosted runners in GitHub Actions. Since ppc64le self-hosted runners are not supported, we will use a workaround to SSH into ppc64le machine from self-hosted x86 runner.
Pre-requisites:
- User account on GitHub
- x86 VM for adding a self-hosted runner to the GitHub repository
- ppc64le VM for executing the GitHub Actions workflow
You can use the PowerVS service at IBM Cloud or Minicloud to get your ppc64le virtual machine. This example uses both centos 8 VMs.
- Install Docker on x86 VM
yum install -y yum-utils
yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repoyum install docker-ce docker-ce-cli containerd.io docker-compose-pluginsystemctl start docker
- Install Docker on Power VM
mkdir /root/docker; cd /root/dockerwget https://download.docker.com/linux/centos/8/ppc64le/stable/Packages/docker-ce-20.10.10-3.el8.ppc64le.rpmwget https://download.docker.com/linux/centos/8/ppc64le/stable/Packages/docker-ce-cli-20.10.10-3.el8.ppc64le.rpmwget https://download.docker.com/linux/centos/8/ppc64le/stable/Packages/docker-ce-rootless-extras-20.10.10-3.el8.ppc64le.rpmwget https://download.docker.com/linux/centos/8/ppc64le/stable/Packages/containerd.io-1.4.11-3.1.el8.ppc64le.rpmyum localinstall containerd.io-1.4.11-3.1.el8.ppc64le.rpm docker-ce-cli-20.10.10-3.el8.ppc64le.rpm docker-ce-20.10.10-3.el8.ppc64le.rpm docker-ce-rootless-extras-20.10.10-3.el8.ppc64le.rpmservice docker start
- Setup Robot user on quay repository
On Quay.io UI, Create a new repository with name test-gh-action-multiarch
. Go to Account settings -> Robot accounts -> Create Robot Account. Once created, give read+write permission to this robot account in your repository settings.
Building multi-arch image workflow
- Setup SSH key authentication
Create SSH key pair if it doesn’t exist by using following steps on x86 VM.
cd ~/.sshssh-keygen -o -t rsa
Add public ssh key to the authorized_keys file of a ppc64le VM.
vi ~/.ssh/authorized_keys
Test SSH connection by using the private key on x86 VM.
ssh -i /root/.ssh/id_rsa username@hostname
2. Clone GitHub repository
Create a new repository or simply fork this repository into your GitHub account.
3. Create a repository secret for customizing your build
Go to Settings > Secrets > Actions > New repository secret and add below variables:
PPC64LE_IP : IP of ppc64le VM
GH_REPO : Name of your GitHub Repo
GH_USER : Your GitHub username
QUAY_REPO : Quay repository username for publishing images eg. quay.io/<user>
ROBOT_USER : Quay Robot user
ROBOT_TOKEN : Quay Robot token
4. Adding a self-hosted runner to a GitHub repository
Follow these instructions for adding a self-hosted runner to the GitHub repository on an x86 machine.
Once your runner is successfully configured and listening for jobs, it will display as idle which means you can execute your workflow.
5. Configure the GitHub Actions workflow
For the very first time, you need to enable a workflow for your GitHub repository, follow this to do that. For triggering the workflow, commit the changes in any of the files of your GitHub repository.
Once the workflow is executed successfully, verify that the multi-arch image is pushed to your quay repository.
That’s all folks! Thanks for reading. Hope this tutorial was helpful.