How to Install Drone CI on Ubuntu 18.04

Updated on July 5, 2019
How to Install Drone CI on Ubuntu 18.04 header image

Introduction

Drone is an automated, continuous testing and delivery platform which runs on your own infrastructure. Drone supports any language, service or database which can run inside a Docker container. The Drone pipeline configuration is written in YAML format in a file named .drone.yml which resides in the root of your project. Drone easily integrates with Github, Gitlab, Bitbucket or Gitea. In this tutorial, we will use Drone with Github.

Requirements

  • Fresh Vultr Ubuntu 18.04 instance with at least 2 GB RAM.
  • Non-root user with sudo privileges.
  • Github account.

Ensure that your system is up to date.

sudo apt update && sudo apt upgrade -y

Step 1: Install Docker CE

Docker provides an easy to use installation script which can be executed on any supported system. It will configure the Docker official repository along with the installation of the Docker Community Edition.

Install the latest version of Docker.

curl -L https://get.docker.com | bash

Once you have installed Docker, add the current user into the docker group so that we can run docker commands from the logged in user.

sudo usermod -aG docker $USER

For the above command to take effect, you will need to log out from the terminal and log back in again.

Test the docker version to ensure we can successfully run the docker command.

docker --version

You will see a similar output.

user@vultr:~$ docker --version
Docker version 18.09.5, build e8ff056

Step 2: Get Github Client ID and Secret

Login to Github and navigate to register a new OAuth application. Provide any name of your choice to the OAuth application. Provide Homepage URL as http://203.0.113.101 and Authorization callback URL as http://203.0.113.101/login. Be sure to replace 203.0.113.101 with your actual Vultr IP address or any domain name pointed towards your Vultr instance.

Once you click the Register application button, you will be given a Client ID and Client Secret.

Make a note of these, as they will be required further in the tutorial.

Step 3: Install Drone CI

Download the latest available version of Drone.

docker pull drone/drone:1

You can always check for the latest tag on the Drone docker hub page.

Create a new environment file to store the Drone configuration.

sudo nano /var/drone.env

Put the following configuration into the editor. Make sure to replace example values with the actual ones.

DRONE_GITHUB_SERVER=https://github.com
DRONE_GITHUB_CLIENT_ID=43ddc12735c28example
DRONE_GITHUB_CLIENT_SECRET=0b8c7c479fefb027758dbdfc5662b7c4example
DRONE_RUNNER_CAPACITY=2
DRONE_SERVER_HOST=http://203.0.113.101
DRONE_SERVER_PROTO=http

Note: DRONE_RUNNER_CAPACITY can be increased according to the RAM available on your instance.

Save the file and exit from the editor.

Start Drone by running the following command.

docker run \
  --volume=/var/run/docker.sock:/var/run/docker.sock \
  --volume=/var/lib/drone:/data \
  --env-file=/var/drone.env \
  --publish=80:80 \
  --publish=443:443 \
  --restart=always \
  --detach=true \
  --name=drone \
  drone/drone:1

That's it. To open the Drone web UI, visit http://203.0.113.101 in your browser and log in using your Github account.