DEV Community

Cover image for Run your own Drone CI
Jim Sheldon
Jim Sheldon

Posted on • Edited on

Run your own Drone CI

Started in 2012, Drone CI is a container-native, event-based, multi-architecture, multi-OS platform for busy teams looking to tighten their software development lifecycles.

Since its acquisition by Harness in August of 2020, Drone CI has made significant improvements in usability and features. Let's see how, in just a few minutes, you can start experimenting with running Drone CI pipelines on any computer running Docker.

Prerequisites

  • Be comfortable running commands in the terminal
  • GitHub account
  • ngrok account
  • Computer that can run amd64 or arm64 Docker containers (this includes the new M1-based Macs)
    • In your terminal, verify you have docker and docker-compose commands available

Overview

Drone CI supports multiple SCM solutions, such as GitHub, Bitbucket, Gitea, GitLab and more.

This guide will focus on GitHub. Because we have chosen GitHub, we need to allow GitHub to send webhooks to the Drone CI process on our computer. We will use ngrok to create a tunnel to the internet so our Drone CI process can receive webhook traffic from GitHub.

Create the ngrok tunnel

  1. Login to https://ngrok.com
  2. Open https://dashboard.ngrok.com/get-started/setup, follow the steps to install the ngrok binary and connect to your account
  3. Create the tunnel by running ngrok http 8080 in your terminal, do not stop the process until you are finished with this guide
  4. ngrok will create your tunnel and provide you with a URL such as https://34f3-146-168-58-81.ngrok.io

Your terminal should display session information similar to this screenshot:

Image description

Create the GitHub OAuth Application

  1. Follow Create an OAuth Application
    • For the "Homepage URL", enter the ngrok URL from the previous step
    • For the "Authorization callback URL", enter the same ngrok URL, with /login appended
    • You will be given the "Client ID" and a "Client secret", make a note of each (the secret is only displayed once, if you misplace it, you will need to generate a new client secret)

Your OAuth application should look similar to this screenshot (for extra authenticity, upload the official Drone CI logo):

Image description

Note: ngrok URLs are temporary with the free plan. If you terminate your ngrok session and create a new one, your URL will change and you will need to update the "Homepage URL" and "Authorization callback URL" in your OAuth Application.

Start the Drone and Drone Runner processes

The Drone server process requires at least one runner process where pipelines will execute. Drone CI supports multiple runners, but the Docker runner is the most popular.

  1. Fork the repository https://github.com/jimsheldon/drone-quickstart and clone the forked repository to your computer
  2. Edit the file run.sh
    • Set DRONE_GITHUB_CLIENT_ID and DRONE_GITHUB_CLIENT_SECRET using the "Client ID" and "Client secret" from the previous section
    • Set DRONE_GITHUB_ADMIN to your GitHub username
    • Set DRONE_SERVER_HOST to your ngrok URL, without the https:// (if your ngrok URL is https://34f3-146-168-58-81.ngrok.io, set DRONE_SERVER_HOST to 34f3-146-168-58-81.ngrok.io)
    • Save your changes
  3. Open a new terminal session and change to the directory where you checked out the repository
    • Execute run.sh by typing ./run.sh and hitting enter
    • Open your ngrok URL in a browser, you should be greeted with "Welcome to Drone"! ๐ŸŽ‰ Image description
    • Click "Continue" and you will be asked to authorize your OAuth application Image description
    • Next you will see the "Complete your Drone Registration" screen Image description
    • Click "Submit" and you will see the Drone CI interface, filter by "quickstart" to see your forked repository Image description
    • Click on the repository, then click "Activate Repository" Image description
    • Your repository should now be activated Image description

Run your first pipeline

  1. Edit the .drone.yml file in the root off your repository. Change the echo hello world message to something of your choice. If your CPU is amd64 (Intel, AMD) you should remove the platform section, which is currently specific to arm64 (Apple M1, Raspberry Pi)
  2. Push your change to a branch and open a pull request
  3. Your pull request will trigger a check in Drone CI called "continuous-integration/drone/pr" Image description
  4. Click the "Details" link, you will see your pipeline execution in Drone CI! Click the "hello" step to see your message printed Image description

You now have your very own Drone CI Enterprise installation! Drone CI Enterprise includes a free trial of up to 5,000 builds. To learn more about licensing options, see the Drone CI Enterprise FAQ.

The official Drone CI documentation provides example pipelines in virtually every language. Try it out on one of your own projects!

Teardown

  1. In the directory where you ran run.sh run docker-compose down.
  2. In the terminal where your ngrok session is running, type CTRL-C.

Note: ngrok URLs are temporary with the free plan. If you terminate your ngrok session, the next time you run ngrok http 8080 your URL will change, and you will need to update the "Homepage URL" and "Authorization callback URL" in your GitHub OAuth Application, as well as the DRONE_SERVER_HOST value in run.sh.

Conclusion

Hopefully this gives you a quick way to get started running Drone CI pipelines from your GitHub repositories.

If you would like to learn more and participate in the Drone CI and Harness communities, here are some helpful links:

Top comments (1)

Collapse
 
pavanbelagatti profile image
Pavan Belagatti

Drone is super easy. Thanks for this tutorial