BuildBot in Docker on a Raspberry Pi 2

Posted by Nathan Osman on June 5, 2015

In a previous article, I took a look at setting up a BuildBot slave on Windows. Today, I’m going to describe the process of creating a BuildBot slave for a Raspberry Pi 2. The easiest way to do this is by setting up the BuildBot slave as a Docker container.

In order to create the container, we need to begin writing a Dockerfile that will install the BuildBot slave and its dependencies. We must also use a custom base image since the Raspberry Pi 2 runs on an ARMv7 processor. Therefore, the first line of the file will look like this:

FROM armhfbuild/ubuntu:14.04

This is not the only armhf image for Ubuntu available on Docker Hub, but this one has worked well for me. Next, we need to install the slave and the build-essential package, which provides a C/C++ compiler and a number of common packages used for building:

RUN \
  apt-get update && \
  apt-get install -y buildbot-slave build-essential && \
  rm -rf /var/lib/apt/lists/*

Our container also needs two additional files added:

COPY buildbot.tac /var/lib/buildbot/slaves/slave/
COPY run.py /root/

You can view the full contents of both of these files in this GitHub repository. I’ll briefly examine each of the files and explain their role below.

The first of these is buildbot.tac, which configures the slave. Since each deployment will need a separate configuration (for host, port, name, etc.), we need a way to pass this information to the container. Docker allows us to do this through environment variables:

from os import environ
BuildSlave(
    environ.get('HOST'),
    environ.get('PORT', 9989),
    ...
)

The second file is run.py, which takes care of starting the BuildBot slave. This script also populates the info/admin and info/host files. Since this is a Python script, it would be quite easy to fetch information about the host (CPU, memory, etc.) and write it to the appropriate file.

We now have everything we need to build the container:

docker build -t buildbot-armhf .

Note: you’ll need to change buildbot-armhf if you plan to upload the container to Docker Hub.

Unfortunately, the command above, although correct, will fail with an error if you attempt to run it in Ubuntu 14.04 on your Pi. This is due to a rather nasty bug which has since been fixed. You will need to install a newer version of Docker on your Pi.

There are a number of different ways to do this. For the sake of convenience, I have built a DEB that you can download and install with:

wget http://files.quickmediasolutions.com/deb/docker.io_1.5.0~dfsg1-1ubuntu2_armhf.deb
sudo dpkg -i docker.io_1.5.0~dfsg1-1ubuntu2_armhf.deb

Now you can try the above command again and it should succeed. Once the container is built, you can run it with the following command:

docker run \
    -d \
    --name buildbot \
    -e HOST=example.org \
    -e NAME=name \
    -e PASSWORD=12345678 \
    -e EMAIL="Me <me@example.org>" \
    buildbot-armhf

You will need to fill in the appropriate values for the environment variables. At this point, the BuildBot slave in the container should connect to your master. You can try forcing a build in order to test that everything is configured correctly.

If your build requires that additional packages be installed, you will need to create another container based on this one. For example, if you need Go installed, create a Dockerfile that contains:

FROM buildbot-armhf
RUN \
  apt-get update && \
  apt-get install -y golang && \
  rm -rf /var/lib/apt/lists/*

You can then build the container with:

docker build -t buildbot-armhf-go .

Now you can use the new container in the same manner as the original one.