Using Docker with Atlassian’s Bamboo for Better Continuous Integration

[article]
Summary:

Some projects built with Bamboo require the build system to have certain specialized software. Installing the software can become a problem when different projects require conflicting sets of software. To solve this, developers can create remote agents with different sets of software and run them all on the same machine with Docker.

Building software to be deployed can be very challenging. Some of the projects we build with the Bamboo continuous integration server require specialized software, such as the Atlassian SDK to be installed. To accomplish this, we install the software on the machine where Bamboo is running, or set up remote build agents on other machines that already have this software. However, this can become a problem when different projects require conflicting sets of software (such as different versions of the Atlassian SDK) or earlier versions of software than what’s already in use on a machine, and there aren’t enough machines to dedicate to builds.

To solve this issue, we create remote agents with different sets of software and run them all on the same machine with Docker. Docker is a virtualization container that allows us to create images of Linux systems, customized in any way one would normally customize Linux, which can then run as self-contained instances or containers. However, this is no easy task, so in this article I’ll give you a detailed view of solving some of the challenges inherent in using containers like Docker for deployment. The only limit on the number of containers for images is resources, as the process is inherently scalable ad infinitum.

Building

A Docker image is constructed from a Dockerfile, which consists of the name of a base image (most often a version of Debian or Ubuntu), a series of commands to run in the base image to customize it, and a CMD line specifying the default command to run when the resulting image is started as a container. For example:

A Docker image is constructed from a Dockerfile

By saving these commands in a file named “Dockerfile” and running the command “docker build -t custom-agent .” in the directory containing the file and, in this case, also containing atlassian-bamboo-agent-installer jar, we create a Docker image named “custom-agent” based on Ubuntu that contains Git, Maven, Java, and a Bamboo remote agent. The ubuntu:14.04 base image is available on the Docker registry and will be downloaded automatically during the image build process if it is not already on the local machine. (Atlassian provides a remote agent Docker image of its own, but it is based on its own custom version of Ubuntu with contents about which they are not forthcoming, so we made our own.) At each subsequent line of the Dockerfile, Docker runs a command inside this image or otherwise modifies it until at the end we have an image to our liking.

Docker RUN runs a command inside the base image just as if we were running it from the command line (specifically, in /bin/sh. Note that each command is run in a separate shell, so RUN cd /path and RUN export VAR=val won’t affect subsequent RUN commands; instead, do WORKDIR /path and ENV VAR val). COPY copies a file (in this case, the Bamboo remote agent JAR) from the local directory containing the Dockerfile into the image. CMD specifies the default command to run when a new container is created from the image. The command used here makes use of an environment variable that will not be set until we run the image.

Pages

About the author

CMCrossroads is a TechWell community.

Through conferences, training, consulting, and online resources, TechWell helps you develop and deliver great software every day.