Host Your Own Continuous Integration Server with Drone

Drone.io is an excellent build and deployment server for modern web applications built (supports Nodejs, Go, PHP, C, Scala and many others). It's integrated with Github and Bitbucket, so with a simple push you can have your repository automatically built, tested and deployed.

Drone has a hosted service that's easy to get started with, but if you wan't more control and your builds and deploys need access to internal resources you can install the open source version on your own server.

Requirements

  • Ubuntu server. Documentation says only Ubuntu 12 and 13 are supported, but Drone is working fine with 14 as well.
  • External IP, ports 80 and 443 open. Drone gets notified of new pushes by the web hooks in Github or Bitbucket, so the Drone server needs to be accessible from the outside.

Installation

The installation is easy enough:

  1. To install drone, just follow the instructions here: http://drone.readthedocs.org/en/latest/install.html. I used the deb package (not source).
  2. Install docker: http://docs.docker.com/installation/ubuntulinux/
  3. Update docker config to allow connections on port 4243, by adding this to /etc/default/docker.io: DOCKER_OPTS="-H tcp://127.0.0.1:4243 -H unix:///var/run/docker.sock"
  4. Restart docker with "sudo service restart docker.io"
  5. Browse to http://yourdroneserver/install to configure the Drone server.

Import Repos

Using Github, Bitbucket or Gitlab you create API tokens for Drone on your account.

  • On Github its under Applications in your account settings. It's a Developer application token you want, not a personal access token.
  • On Bitbucket under Manage account you create a token in the OAuth section.

Once you've added the tokens you can import your first repo.

If pushes to your repo don't show up in Drone, it could be that you're missing a .drone.yml file (see below).

Create Deployments

  1. Add a file called .drone.yml in the base directory your repo.
  2. Select a docker image that will be used on the Drone server to build and test your repo before deploy. https://github.com/drone/drone#images. Add your selected image to the .drone.yml file (i.e. 'image: bradrydzewski/node:0.10)
  3. Add stuff needed for test, build and deploy in the .drone.yml file. See below.
  4. Push to your repo and watch the magic happen. The first build will probably take a while since the docker image of about 3,5 GB is downloaded (it is reused on subsequent builds).

.drone.yml

The documentation on the format of the .drone.yml file is really abysmal completely missing and you have to trial and error your way a bit here. We ended up basically using the script: section for now and put both build, test and deploy commands there.

Our first working .drone.yml looks something like this:

image: bradrydzewski/node:0.10

script:
  - npm -q install
  - npm -q -g install gulp
  - gulp test
  - gulp deploy --$DRONE_BRANCH --$DRONE_COMMIT

notify:
  email:
    recipients:
	  - anders.bornholm@iteam.se

So gulp does the actual deployment in this case - the gulp deployment task transfers files and runs commands on the deployment server using ssh.

Drone has ssh support, but we can't use that because we need to convert the branch name into an environment name based on a set of rules - for instance all branches starting with "release/" are going into the "stage" environment. There are no real features for conditionals or manipulations in drone.yml.

Pros and Cons of Hosting Drone Yourself

Pros

  • Full control over the environment
  • Pay per server (your own hardware) instead of per repo
  • Can access internal resources

Cons

  • Features missing compared to hosted version (branch filters, plugins like ssh deploy etc).
  • Scarce documentation, almost all online resources refer to the hosted version

Next step

In my next post I will describe how we set up the gulp tasks to deploy via ssh onto our own servers. In the meantime, good luck!

comments powered by Disqus