Self-made continuous integration with Travis CI

In the post How to Run your Travis Build locally we did the heavy work ourself.

The original setup was fine to debug a Travis CI job locally - once in a while.

Why don't go a step further and setup a continuous integration pipeline ourself?

Travis CI

Free continuous integration platform for GitHub projects.

With this series of post we'll look deeper into how to setup a self-made continuous integration with Travis CI.

We start with the easy part: Automate android builds...

Let's do some plumbing!

At this point we assume Docker is already up and running.

The components will use a message queue to communicate with each other:

$ docker run -d \
    --restart=always \
    --hostname travis-rabbitmq \
    --name travis-rabbitmq \
    rabbitmq:3.6.11-management-alpine

You might want to publish some ports --publish 5672:5672 --publish 15672:15672 to make them available from outside the host. The RabbitMQ Management will be accessible via http://localhost:15672/#/. Creating a custom RabbitMQ container with preconfigured queues can be automated, too.

TravisCI components - available from Github - are next on the list:

  • travis-build - creates the build script for each job. It takes the configuration from the .travis.yml file and creates a bash script that is then run in the build environment by travis-worker.
  • worker - Worker is the component of Travis CI that will run a CI job on some form of compute instance. It's responsible for getting the bash script from travis-build, spin up the compute instance (VM, Docker container, or maybe something different), upload the bash script, run it and stream the logs back to travis-logs. It also sends state updates to travis-hub.

The travis-build component comes first:

$ git clone https://github.com/travis-ci/travis-build.git
$ cd travis-build
$ docker build -t travis-build .
$ docker run -d \
    --restart=always \
    --name travis-build \
    --publish 5000:5000 \
    -e PORT=5000 \
    travis-build

With the following snippet:

{
  "config":{
    "language":"ruby",
    "os":"linux",
    "script":[
      "bundle exec rake"
    ]
  },
  "job":{
    "branch":"master",
    "commit":"a15c1259aeaf8e1955f01ed53abfa7cc5ef5e640",
    "tag":null
  },
  "queue":"builds.macstadium6",
  "repository":{
    "slug":"travis-repos/chirp-org-staging",
    "source_url":"https://github.com/travis-repos/chirp-org-staging.git"
  },
  "vm_type":"default"
}

we can test the configuration (given you save the snippet above as travis-build-test.json and travis-build is running on localhost).

$ curl -d "@travis-build-test.json" localhost:5000/script > test-script.sh

If you get back a shell script the first part of the setup is finished.

That was the first part...in the next post we'll guide you through the logical next step: Setting up a TravisCI worker locally.

Show Comments