Getting started with Drone CI, the open source solution

If you're building a personal project or a startup and don't want to spend too much on popular commercial solutions like Travis CI (which costs $69/month), you can set up your own self-hosted Drone CI on your laptop, on AWS's free tier, or on any other server.
Drone CI features:
- Cross-platform support
- YAML-based configuration
- Support for multiple pipelines and complex logic in build steps
- Docker-based
- Free
- Support for GitHub, GitLab, and Bitbucket
We're going to run Drone CI on a single host with GitHub, but you could also use a multi-machine or Kubernetes setup, and other version control providers. You'll find more information in the official documentation.
Get a host
For this test we're using an AWS free-tier EC2 instance, but you can use whatever you like. If you want to follow the same approach, follow these steps:
- Go to the AWS website;
- Add your public SSH key under Key Pairs on the EC2 page (to access your instance over SSH);
- Create a new free-tier Ubuntu 18.04 instance on AWS;
- Open ports 80 and 443 in your instance's Security Group; if the account is new, use launch-wizard-1, or look it up in your EC2 instance's description.
Install Docker
To start using Drone you only need Docker. Follow the instructions in its official documentation. Check that everything installed correctly by running "docker -v".
root@ip-172-31-23-205:~# docker -vDocker version 18.09.3, build 774a1f4
Create an OAuth app
In the examples we use GitHub, but you can also use GitLab, Bitbucket, Gitea, and Gogs. You'll find more information in Drone's documentation.
- Go to github.com/settings/developers and log in to your personal account, if you already have one, or create one if you don't.
- Click "new oAuth app."
- Fill in the form as shown in the example below.
To fill in this form correctly, you can use your server's IP or assign it a domain. Once done, you'll be able to use the Client ID and Client Secret in the following steps.
Install Drone
It's very simple, just this:
docker pull drone/drone:1
And then:
--volume=/var/run/docker.sock:/var/run/docker.sock \ --volume=/var/lib/drone:/data \ --env=DRONE_GITHUB_SERVER=https://github.com \ --env=DRONE_GITHUB_CLIENT_ID=652d1he1a62b6336bf0 \ --env=DRONE_GITHUB_CLIENT_SECRET=c8990176a4bfywe55ekj8c3cf6d0ffccb8e3a213e \ --env=DRONE_RUNNER_CAPACITY=2 \ --env=DRONE_SERVER_HOST=drone1.example.com \ --env=DRONE_SERVER_PROTO=https \ --env=DRONE_TLS_AUTOCERT=true \ --env=DRONE_USER_FILTER=your-username \ --env=DRONE_USER_CREATE=username:your-username,admin:true \ --publish=80:80 \ --publish=443:443 \ --restart=always \ --detach=true \ --name=drone \ drone/drone:1
With this configuration, Drone generates SSL certificates with Let's Encrypt, letting us access the Drone interface over https. Your user account will have admin privileges (DRONE_USER_CREATE), and it's a good idea to block server access for anyone else (DRONE_USER_FILTER). You'll find the rest of the variables explained in Drone's documentation.
Your instance should now be up and running: log in and start using it!
Define your pipeline
With your Drone CI instance ready, it's time to activate the repository and create your pipeline. First, find the repository in the search bar and activate it.
On the settings page you can change the project's visibility, add secrets (sensitive information needed by the build steps), or add a cron job.
Defining build steps and pipelines in Drone is very simple. You just need to add a .drone.yml file to your repository and describe the steps using YAML syntax. Here's a simple example:
kind: pipelinename: defaultsteps:- name: frontend image: node commands: - npm ci - npm run test:unit
Now, every time you push to the repository, a new build will trigger in Drone CI.
But you can do a lot more, depending on how complex your project is. Here are some typical uses:
- Sending notifications to Slack
- Deploying to Kubernetes
- Pushing images to a Docker registry
- Spinning up databases or other services needed for tests
- Running multiple pipelines and working across several platforms
Drone is a day-to-day ally that greatly improves stability, flexibility, and convenience when running tests and deploying code. To learn more about Drone CI, visit drone.io/.