Monday, July 6, 2015

Provisioning Buildbot Master-Slave Containers with Docker

Now that we're more familiar with setting up Buildbot and the master.cfg, we can move forward with this alternative, container-based approach, using Docker. I strongly urge you to go through the prerequisites in in article because you'll need to carry over your master and slave configuration. Let's start there.

Prerequisites: Read Provisioning Builbot with Vagrant and Ansible, and make sure you've prepared your Docker Host and are familiar with Docker Machine.

Spinning Up the Instances with Docker Compose

To make it easy on ourselves, we're going to create a manifest for all the necessary containers using with a docker-compose.yml file.

# clone the repo
git clone git@github.com:roblayton/docker-compose-files
cd docker-compose-files/buildbot

# spin up the instances
docker-compose up

Example docker-compose.yml Files

When you clone the docker-compose-files repo, you'll get the following buildbot/docker-compose.yml file:

storage:
  build: .
  volumes:
    - /master
    - /slave
bbmaster:
  image: roblayton/buildbot-master
  volumes_from:
    - storage
  ports: 
    - "8010:8010"
    - "9989:9989"
bbslave:
  image: roblayton/buildbot-slave
  links:
    - bbmaster:bbmaster
  environment:
    MASTER: "bbmaster:9989"
    SLAVE_NAME: example-slave
    SLAVE_PASSWORD: pass
  volumes_from:
    - storage

If you run this for the first time with the default set up and without a prepared master and slave configuration (more about this later), the following operations will take place:

  • The data-only storage container will map the /master and /slave volumes to the host

  • Because the /master directory is empty, buildbot will create a new master and fill it with the necessary files
  • Because the /slave directory is empty, buildbot will create a new slave and fill it with the necessary files
  • By using the default master files, we have to set the SLAVE_NAME and SLAVE_PASSWORD

Warning: Do not roll out with this set up in production!

Instead, use these other set of steps to set up buildbot, locally, and prepare your master and slave configurations, first. Then, overwrite the /master and /slave directories in docker-compose-files/buildbot with your own. Lastly, uncomment the following lines in docker-compose-files/buildbot/Dockerfile will which make sure the proper directories get copied over to the data-only storage container:

FROM busybox
MAINTAINER Rob Layton <hire@roblayton.com>

# uncomment to use pre-existing configs
# COPY ["master", "/master"]
# COPY ["slave", "/slave"]

Docker Registry Repos

In case you were curious, we're using the following Docker images:

Debugging

In case you want to check logs, enter the containers and dig around, or teardown the instances in order to re-initialize with new configurations, use the following commands:

# check the master logs
docker logs buildbot_bbmaster_1

# check the slave logs
docker logs buildbot_bbslave_1

# open up a new bash session in the master
docker exec -it buildbot_bbmaster_1 /bin/bash

# open up a new bash session in the slave
docker exec -it buildbot_bbslave_1 /bin/bash

# remember this is an option
docker-compose rm

No comments:

Post a Comment