If Travis and Docker are part of your CI workflow and your development, staging, test, or production environment involve multiple CPU architectures, this article will be of interest to you.

We will see how to use Travis to build a Power (ppc64le) Docker image by using Docker and Qemu. Currently, Travis natively supports only Intel slaves and thereby supports building of Intel (amd64) Docker images only.

We will use Qemu user mode emulation that enables running binaries compiled for one CPU architecture on another CPU architecture. To use Qemu user mode emulation to run Power (ppc64le) binaries on Intel (amd64) cpu, we will need to register the appropriate Qemu binary as the interpreter/handler for any Power (ppc64le) binaries.

The following command registers /usr/bin/qemu-ppc64le-static as the interpreter for running ppc64le binaries.

$ sudo docker run --rm --privileged multiarch/qemu-user-static:register

 
The next step is to download the Qemu binary.

$ wget https://github.com/multiarch/qemu-user-static/releases/download/v2.9.1/qemu-ppc64le-static.tar.gz -O /tmp/qemu-ppc64le-static.tar.gz
$ tar zxvf /tmp/qemu-ppc64le-static.tar.gz -C /tmp

 
Now, to run a ppc64le Docker image, all we need is to mount the Qemu binary inside the container at the path /usr/bin/qemu-ppc64le-static when running the container. For example,

$ sudo docker run -v /tmp/qemu-ppc64le-static:/usr/bin/qemu-ppc64le-static -it ppc64le/hello-world

 
If you are interested to know more on this, refer to the Approaches to build and test PowerPC Docker Images on Intel System blog.

To build a ppc64le Docker image using the above mechanism, we need a way to mount the Qemu binary inside the container during the image build process. In other words, we need an equivalent of a volume mount (-v) option with docker build. The patches required to support this functionality is still work in progress – https://github.com/moby/moby/issues/32507.
However, for test and evaluation, we have provided a custom docker-engine binary that you can try from the following repository – http://ftp.unicamp.br/pub/linuxpatch/ubuntu/14_04/misc/docker-17.04.0-ce-amd64/

After you have installed the custom docker-engine binary, complete the following steps to build a ppc64le Docker image:

$ git clone https://github.com/bpradipt/docker-mysql.git
$ cd docker-mysql
$ sudo docker build --volume type=bind,source=/tmp/qemu-ppc64le-static,target=/usr/bin/qemu-ppc64le-static -f Dockerfile.ppc64le -t ppc64le/mysql .

 
Note: The ‘--volume’ option is available in the custom docker-engine.

For leveraging the above approach with Travis, we need to include the relevant steps in the travis.yml file.

The following is a sample travis.yml file to demonstrate the complete workflow. You can find the example github project here: https://github.com/bpradipt/docker-mysql.git.

sudo: required
services:
  - docker
before_install:
  - sudo apt-get update
  - sudo apt-get install -y wget git
  - sudo apt-get remove docker-ce
  - echo "deb [arch=amd64 trusted=yes] http://ftp.unicamp.br/pub/linuxpatch/ubuntu/14_04/misc/docker-17.04.0-ce-amd64/ trusty main" | sudo tee /etc/apt/sources.list.d/docker-engine.list
  - sudo apt-get update
  - sudo apt-get install -y docker-engine
  - docker run --rm --privileged multiarch/qemu-user-static:register
  - wget https://github.com/multiarch/qemu-user-static/releases/download/v2.9.1/qemu-ppc64le-static.tar.gz -O /tmp/qemu-ppc64le-static.tar.gz
  - tar zxvf /tmp/qemu-ppc64le-static.tar.gz -C /tmp
  - git clone https://github.com/bpradipt/docker-mysql.git
  - cd docker-mysql
  # Build Power(ppc64le) Docker image
  - docker build --volume type=bind,source=/tmp/qemu-ppc64le-static,target=/usr/bin/qemu-ppc64le-static  -f Dockerfile.ppc64le -t ppc64le/mysql .
  # Build Intel(amd64) Docker image
  - docker build -f Dockerfile -t amd64/mysql .
install: true
before_script: true
script: docker images
after_script: true

 
Using the above approach, you can easily perform the following steps as part of the build process:

  1. Pull ppc64le Docker images from the registry and run them up as part of your build.
  2. Set up a ppc64le build environment for running tests.
  3. Build a ppc64le Docker image and push it to registry.

1 comment on"Travis with Docker and QEMU for multi-architecture CI workflow"

  1. […] with Docker and Qemu for  multi-architecture CI workflow – https://developer.ibm.com/linuxonpower/2017/07/28/travis-multi-architecture-ci-workflow This article describes how Docker and Qemu can be combined to have a multi-architecture CI workflow […]

Join The Discussion

Your email address will not be published. Required fields are marked *