Building multi-arch images using GitLab
GitLab is a single application DevOps platform that is designed to manage the entire software development lifecycle. It enables professionals to perform all the tasks in a project — from project planning and source code management to monitoring and security. Additionally, it allows teams to collaborate and build better software.
The GitLab Runner includes support for Linux on IBM Power and provides built binary files and images for GitLab Runner from GA 14.3 release onwards. Whereas GitLab Runner operator includes support for IBM Power from v1.6.0 onwards.
In this blog, we will see how to build multi-arch images with the help of simple GitLab pipeline.
Pre-requisites
- IBM Power resource to setup GitLab Runner for building ppc64le image
You can use the PowerVS service at IBM Cloud or Minicloud to get your ppc64le virtual machine. This example uses a Centos 8 ppc64le VM.
- x86 resource to setup GitLab Runner for building x86 image
You can use amd64(x86) VM on IBM Cloud or use shared runners provided by GitLab. This example uses Centos 8 x86 VM.
- 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
- Add permission to execute docker commands on x86 and Power runners
sudo usermod -aG docker gitlab-runnersudo service docker restart
- Setup Robot user on quay repository
On Quay.io UI, Create a new repository with name test-gitlab
. 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 images
- Import GitLab pipeline source code
Create a GitLab account at https://gitlab.com/users/sign_up/ if you are a new user. If you already have an account, sign in using your credentials. On the top section, select Menu -> Projects -> Create new Project. Next, select Import Project -> Repository by URL. Next, enter the Git Repository URL as https://gitlab.com/skanekar1/gitlab-multiarch and name your repository. Once all the details are entered, select visibility as per your need(Public to avoid authentication) and create project.
2. Install GitLab Runner on x86 and Power VMs
curl -LJO "https://gitlab-runner-downloads.s3.amazonaws.com/latest/rpm/gitlab-runner_<arch>.rpm"rpm -i gitlab-runner_<arch>.rpmgitlab-runner --version
Replace <arch> value with appropriate architecture value. You can refer this documentation for installing GitLab Runners.
3. Register runners on x86 and Power
gitlab-runner register
Copy your GitLab instance URL and project token from your project settings : Settings -> CICD -> Runners.
Select executor type as shell. Add tag for respective architecture runners. In this tutorial, we will be using tag as x86(for x86 runner) and ppc(for ppc64le runner).
Once the registration is complete, refresh the Runners setting page to verify that the runners are successfully registered.
4. Set required environment variables in GitLab
Go to Settings -> CICD -> Variables and set below environment variables:
ROBOT_USER : Quay Robot User
ROBOT_TOKEN : Quay Robot Token
QUAY_REPO : Quay repo to publish the images eg. quay.io/<user>
5. Execute pipeline
Go to CICD -> Pipelines and select Run Pipeline on main branch.
6. Verify and test multi-arch images on quay.io
You can test the multi-arch image on x86 and Power:
docker pull quay.io/snehakpersistent/test-gitlab:multi-arch-gitlab-latest
Thats all folks! Thanks for reading. Hope this tutorial was helpful :)