Drone is a free and open source project which provides an awesome environment of continuous integration service and is released under Apache License Version 2.0. It integrates with many repository providers like Github, Bitbucket and Google Code and has the ability to pull codes from the repositories enabling us to build the source code written in number of languages including PHP, Node, Ruby, Go, Dart, Python, C/C++, JAVA and more. It is made such a powerful platform because it uses containers and docker technology for every build making users a complete control over their build environment with guaranteed isolation.
Let’s assume that you have Ubuntu 14.04 or Ubuntu 16.04 or other Linux distro with routable IP address. Or you can buy a VPS in amazon or digital ocean.
In order to run Drone, we must setup at least one integration points between GitHub, GitHub Enterprise, Gitlab, Gogs, Bitbucket.
Step 1: install Docker
On your Ubuntu machine, run this:
# curl -s https://get.docker.io/ubuntu/ | sudo sh
You can verify the installation with:
# docker run -i -t ubuntu /bin/bash
Step 2: install Drone
Now let’s install drone from deb file. Which you can download from their own portal.
# wget downloads.drone.io/master/drone.deb
# dpkg -i drone.deb
Once you installed the drone, you can modify configuration in /etc/drone/drone.toml file, which main configuration for drone in Linux. Like you can edit ports and add your client details etc.
By default drone uses port 80, if you want to edit, you can edit following field in drone.toml file.
Step 2: Register a new application on GitHub
You now have Drone up and running, but we need to configure GitHub access so that it can setup hooks to build your code after code push or pull requests. First step for that is to register a new application on GitHub. From this URL https://github.com/settings/applications/new
- Give any name for your application. I give “My drone
- Set the homepage URL to http://server-ip-or-addr/
- The description is just about your application. You can give what you want.
- The authorization callback URL should be set to http:// server-ip-or-addr /api/auth/github.com
Step 3: get your GitHub client ID & secret configured in Drone
After the registering your new app on GitHub, you were given a client ID and secret, copy them in the /etc/drone/drone.toml file. You can fine github field in that like below
Step 4: link your project
Click on the “New Repository” button (which will get you to http://my-server-ip-or-addr/new/github.com), click “Link Now”, accept and then once on the “Repository Setup” page of Drone, you get to fill the repository details (GitHub owner + repository name).
Boom! Your project is almost ready to be built. You need only one final step now…
Step 5: configure your .drone.yml
The .drone.yml file is the configuration file for the build steps, services, notifications, etc.
Here is a simple example for a Ruby on Rails project:
– go get
– go test -cover ./…
– go build
services: – Go App
There is a variety of images for Go, Python, Haskell, PHP, Scala, Node, etc. Drone provides us with official images but you are not restricted to only those.
When you are done, commit, push and watch the build. Rinse & repeat until your.drone.yml is working just fine.
Iptables is a popular firewall program which is installed in the ubuntu distributions by default. We’ll make iptables to expose port 80 so that we can make our Drone web interface accessible in the network.
# iptables -A INPUT -p tcp -m tcp –dport <<port no>> -j ACCEPT
# /etc/init.d/iptables save
Drone offers few more option which we may helpful some scenarios:
- Email notifications (Configure SMTP & give mail server details in drone.toml file)
- SSL configuration also available, which helps to secure the environment. You can add SSL certs details on drone.toml file (line 6)
- Continuous deployment options also available.