Setting up a TravisCI worker locally

In the previous post we've setup the required infrastructure: (Self-made continuous integration with Travis CI) The worker requires a bit more configuration.

Anyway let's create the worker Docker image first. We will create it with the help of the following Dockerfile-travis-worker-2.7.0:

FROM alpine:3.4

ADD https://github.com/travis-ci/worker/releases/download/v2.7.0/travis-worker-v2.7.0-linux-amd64 /usr/local/bin/travis-worker

RUN chmod u+x /usr/local/bin/travis-worker

VOLUME ["/var/tmp"]

ENTRYPOINT ["/usr/local/bin/travis-worker"]

Then build the Docker image with the following command:

$ docker build -f Dockerfile-travis-worker-2.7.0 . -t worker

This will result in a rather small Docker image.

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
worker              latest              2013b5dd3fe3        2 minutes ago       40.1 MB

A first check:

$ docker run -it --rm --user root worker --help
NAME:
   travis-worker - Travis Worker

USAGE:
   travis-worker [global options] command [command options] [arguments...]

VERSION:
   v2.7.0
....

Nice.

Let's continue with the fine-tuning...

$ export HOST_IP=192.168.47.11
$ docker run -d \
    --name travis-worker \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -e "TRAVIS_WORKER_DOCKER_ENDPOINT=unix:///var/run/docker.sock" \
    -e "TRAVIS_WORKER_DOCKER_NATIVE=true" \
    -e "TRAVIS_WORKER_DOCKER_CPUS=0" \
    -e "TRAVIS_WORKER_AMQP_URI=amqp://${HOST_IP}" \
    -e "TRAVIS_WORKER_QUEUE_NAME=android.queue" \
    -e "TRAVIS_WORKER_BUILD_API_URI=http://${HOST_IP}:5000/script" \
    worker

Since we want to be able to run Android builds locally we need the TravisCI base image. Travis will look for travis:android.

$ docker pull quay.io/travisci/travis-android
$ docker tag quay.io/travisci/travis-android:latest travis:android