Seven Story Rabbit Hole

Sometimes awesome things happen in deep rabbit holes. Or not.

   images

Setting Up a Self-hosted drone.io CI Server

Spin up AWS server

  • Ubuntu Server 14.04 LTS (HVM), SSD Volume Type – ami-fce3c696
  • m3.medium
  • 250MB magnetic storage

Install docker

ssh ubuntu@<aws-instance> and install docker

Register github application

Go to github and register a new OAuth application using the following values:

It will give you a Client ID and Client Secret

Create /etc/drone/dronerc config file

On the ubuntu host:

1
2
$ sudo mkdir /etc/drone
$ emacs /etc/drone/dronerc

Configure Remote Driver

Add these values:

1
2
REMOTE_DRIVER=github
REMOTE_CONFIG=https://github.com?client_id=${client_id}&client_secret=${client_secret}

and replace client_id and client_secret with the values returned from github.

Configure Database

Add these values:

1
2
DATABASE_DRIVER=sqlite3
DATABASE_CONFIG=/var/lib/drone/drone.sqlite

Run Docker container

1
2
3
4
5
6
7
8
9
sudo docker run \
  --volume /var/lib/drone:/var/lib/drone \
  --volume /var/run/docker.sock:/var/run/docker.sock \
  --env-file /etc/drone/dronerc \
  --restart=always \
  --publish=80:8000 \
  --detach=true \
  --name=drone \
  drone/drone:0.4

Check the logs via docker logs <container-id> and they should look something like this

Edit AWS security group

With your instance selected, look for the security groups in the instance details:

screenshot

Add a new inbound port with the following settings:

  • Protocol TCP
  • Port Range 80
  • Source 0.0.0.0

It should look like this when you’re done:

screenshot

Verify it’s running

Paste the hostname of your aws instance into your browser (eg, http://ec2-54-163-185-45.compute-1.amazonaws.com), and you should see a page like this:

screenshot

Login

If you click the login button, you should see:

screenshot

And then:

screenshot

Activate a repository

Click one of the repositories you have access to, and you should get an “activate now” option:

screenshot

which will take you to your project home screen:

screenshot

Add a .drone.yml file to the root of the repository

In the repository you have chosen (in my case I’m using tleyden/sync_gateway, which is a golang project, and may refer to it later), add a .drone.yml file to the root of the repository with:

1
2
3
4
5
6
build:
  image: golang
  commands:
    - go get
    - go build
    - go test

Commit your change, but do not push to github yet, that will be in the next step.

1
2
$ git add .drone.yml
$ git commit -m "Add drone.yml"

Kickoff a build

Now push your change up to github.

1
$ git push origin master

and in your drone UI you should see a build in progress:

screenshot

when it finishes, you’ll see either a pass or a failure. If you get a failure (which I did), it will look like this:

screenshot

Manually triggering another build

In my case, the above failure was due to a dependency not building. Since nothing else needs to be pushed to the repo to fix the build, I’m just going to manually trigger a build.

On the build failure screen above, there is a Restart button, which triggers a new build.

screenshot

Now it works!

Setup the Drone CLI

I could run this on my OSX workstation, but I decided to run this on a linux docker container. The rest of the steps assume you have spun up and are inside a linux docker container.

1
2
$ curl http://downloads.drone.io/drone-cli/drone_linux_amd64.tar.gz | tar zx
$ install -t /usr/local/bin drone

Go to your Profile page in the drone UI, and click Show Token.

Now set these environment variables

1
2
$ export DRONE_SERVER=http://ec2-54-163-185-45.compute-1.amazonaws.com
$ export DRONE_TOKEN=eyJhbGci...

Query repos

To test the CLI tool works, try the following commands:

1
2
3
4
5
# drone repo ls
couchbase/sync_gateway
tleyden/sync_gateway
# drone repo info tleyden/sync_gateway
tleyden/sync_gateway

Comments