DevSecOps and Automation on Power

 View Only

Cross-compiling using GitHub Actions and QEMU

By Sneha Kanekar posted Mon September 19, 2022 02:21 PM

  

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. However, if you don’t have the hardware resources with required OS or architecture to host your own runners, then you can QEMU emulator that uses the current operating system to run other architectures. 

In this blog, I will share the approach I used to cross-compile open source packages using GitHub Actions and publish the built artifact as a release. We shall refer to this repository created for building Terraform for the ppc64le (Power) architecture.

Create Build script

First, create a build script that will install required dependencies, clone the package repository and execute commands for building the package binary in the required environment. In this example, I have created a script build.sh used for building Terraform for Power architecture.

Create workflows in GitHub Actions

Create workflows to detect new official release of the package and build the package binary to be published as a release for required OS or architecture.

  1. Polling official package repository
    The aim of this workflow is to poll the official source code repository of the package to detect if there is any new release. Compare the latest release from official source with the latest release in your local repository. If new release is detected, then trigger the workflow to build new release for your required environment. In this example, I have used cron job to schedule this workflow. Refer this workflow used for polling the official Terraform repository.
  2. Building and publishing a new release
    This workflow will be triggered only when the previous workflow detects a new release in the official package repository. The goal here is to simply build the new version of the package in the required environment. In this approach, I have used GitHub Action run-on-arch-action which is responsible for executing commands on non-x86 architectures via QEMU. It takes architecture, distribution, and commands to be executed as input parameters. In this example, we are mounting volumes to save the built artifact for Terraform.

Next, we need to create release for the artifacts built in the required environment. In this approach, I have used GitHub Action release-action for creating release and uploading built artifact to it. This action also allows release updates.

That’s all folks! Thank you for reading. I hope you found this tutorial helpful :)

Originally published on Medium.com

Permalink