Constant Integration with Drone

Philippe Lafrance
3 min readNov 10, 2016

Setupping CI is a struggle for many organizations. In this article, I’ll show how to setup drone for CI.

Why drone?

I first found drone when searching for a CI tool that could replace travis to run closed-source projects. One of the things I was looking for was to store configs in a file in the repo, and have as little config as possible to do inside the actual CI tool. Drone is open source, and leverage docker to setup test environments. Its also much lighter and straightforward to use than Jenkins.

Install docker on a VPS

First of all, install docker and docker-compose. I won’t cover the specifics here. You most likely want to install this stuff on a VPS. I like taking a 5$/month VPS on DigitalOcean that comes pre-installed with docker.

Setup Drone

Drone comes as a docker image. You can find a long-ass command in their doc on how to run it. If you’re like me, you probably can’t remember all of the arguments by heart. So lets create a compose file and save it all inside once and for all.

Setup github (or your adapter of choice)

You must register your application with GitHub in order to generate a Client and Secret. Navigate to your account settings and choose OAuth Applications from the menu, and click Register new application.

Home Url: http://{your vps ip here}/
Authorization callback URL: http://{your vps ip here}/authorize

Press save, you’ll be given a client id and a client secret. Get back to your VPS and create a file with the name .env, inside of it paste the following inside.

REMOTE_DRIVER=github
REMOTE_CONFIG=https://github.com?client_id=...&client_secret=...

If you use a different host than github, you can use one of the other drivers available.

Start your drone server

This should be as easy as running the command

docker-compose up -d

You should see the Drone login screen when visiting the ip of your VPS. You can use regular docker commands to control the drone server. For example

# Shutdown the server
docker-compose down
# Inspect the logs
docker-compose logs
# Update drone to a new version
docker-compose build
docker-compose restart

Pick a docker image

Choose a docker image that can run your test suite. The image should have everything inside allowing it to run the tests. For this example, I’ll pick a docker image that can run a CakePHP project like this one. It has all of the dependencies neede for Cake.

However, drone works by running your image and passing all of the commands inside. In this example, that means also downloading all dependencies with composer. And since I don’t really want my package manager and my dev-dependencies inside my production image, I’ll base another image off of the one above, and add composer, git and zip extensions. You can see this image here, and that’s what we’ll use for tests.

Finally, add a .drone.yml config to your repo

Add a config fill that will instruct drone on how to run your test suite.

You can now log on your VPS on drone, and add your repo to the activated repos. Every time you push, you should see a new build running automatically.

There are many fancy things you can do with drone, and plugins you can install. Refer to the doc if you need inspiration :)

--

--