How to Install Drone CI for Gitea
Published: 2020-05-17 22:51:18


# How to Install Drone CI for Gitea

Welcome! This is a simple tutorial that is heavily based on Drone’s documentation with a minor focus on Oracle Cloud. Without further ado, let’s get into it!

## Prerequisites

* Basic computer literacy

* An [Oracle Cloud](https://www.oracle.com/cloud/free/) account (Any provider such as AWS or GCP with work just as well), since that’s what we’ll be using here

* An existing Gitea server

* A domain name and access to your DNS records

If you chose to use GCP, you can follow my Gitea tutorial for the networking bits found [here](https://dev.to/kylejschwartz/hosting-gitea-on-google-cloud-platform-384f).

If you don’t have a Gitea sever, you can follow the aforementioned tutorial to get one setup.

It is important to run this on a **DIFFERENT** server than your Gitea instance. Thankfully, Oracle offers 2 VMs for free so that shouldn’t be a problem!

## Generate SSH Keys

![](https://cdn-images-1.medium.com/max/2000/1*xzWKlMfEpWIstKghgporQA.png)

1. Login to your Oracle Cloud

1. Open the Cloud Shell by pressing the console icon in the top right corner

1. Wait a few moments and then run the following command in the console at the bottom of the page:
`ssh-keygen -t rsa -b 4096 -C "*your_email@example.com*"`
replacing your_email@example.com with your real email. Leave the quotation marks!

1. The console will ask you where you want to save the key. Just press enter.

1. When prompted to enter a password, simply leave it blank and just press enter.

1. Now that your keys are generated, we need to view our public key by entering the following command into the console:
`cat .ssh/id_rsa.pub`

1. This will display our public key in the console. It will begin with ssh-rsa and end with you email. Select the entire block of text, around 3 lines, including ssh_rsa and your email. Copy this, as we will need it to setup our VM and Console Connection.

## VM Setup

1. Click on the hamburger menu (☰) > Compute > Instances

1. Click `Create Instance`

1. Name your instance as you choose, I prefer “Drone”

1. Click `Change Image` and select `Canonical Ubuntu 18.04`. Scroll to the bottom and click `Select Image`

1. Click `Paste SSH Keys` and paste the key you copied from the previous section.

1. Click `Create` and wait for your instance to be fully setup (The icon will turn green)

1. Now, write down the public IP address under `Instance Access`. We will need this down the line.

## Networking

### Console Connections

1. Scroll to the bottom of your instance page, and click `Console Connections`

1. Click `Create Console Connection`

1. Click `Paste SSH Key` and paste in the same key from the last section.

1. Click `Create Console Connection` and wait a few seconds

### Virtual Cloud Network

1. At the top of the instance page, below the `Instance Details` section, click on the blue link similar to `VirtualCloudNetwork-00000000–0000`

1. On the left side, below the green hexagon, click on `Security Lists (1)`

1. Click on `Default Security List for VirtualCloudNetwork-00000000–0000`

1. Click `Add Ingress Rule` and add the two rules below one at a time:
 — — — — 
Rule 1:
Source CIDR: 0.0.0.0/0
Destination Port Range: 80 
 — — — — 
Rule 2:
Source CIDR: 0.0.0.0/0
Destination Port Range: 443
 — — — — 
Leave all other fields as-is

## Connecting to the VM

1. Using the Cloud Console once more, we need to edit the permissions of our Private SSH Key by entering the following into the console:
`chmod 400 .ssh/id_rsa`

1. Now, using the public IP address from awhile ago, enter the following command, substituting “address” for the VMs IP address:
`ssh –i .ssh/id_rsa ubuntu@address`

## Random Config Note

Before going to the next step, I HIGHLY recommend going into the DNS of your domain and configuring drone.yourwebsite.com to the public IP of your VM. If you’re using cloudflare, DON’T PROXY, use DNS ONLY. Thank you, you may continue now.

## Installing Drone CI

First, you need to install docker. Follow [this](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-18-04) tutorial from DigitalOcean. You only need to follow everything in step 1.

Once you have docker installed, we are going to open a new tab and go to our Gitea website. You might need an admin account for this part.

1. Click on the profile icon in the top right and click `Settings`

1. Click on the “Applications” tab and scroll down to the `Manage OAuth2 Applications` section

1. Enter “Drone” as your Application Name, and “http://drone.yourwebsite.com/login” as the Redirect URI, then click `Create Application`

1. You will now we shown your Client ID and your Client Secret. Write down or copy the Client Secret as it won’t be shown again. Client ID will always be viewable.

1. Now, head back to your Cloud Console (You should still be logged into the VM) and we are going to generate a shared secret by running the following command:
`openssl rand -hex 16`
Save the output of this command as we will need it later

1. Now we will download drone itself by running this command:
docker pull drone/drone:1

1. The easiest way to do this next step is to copy the code below into Notepad or TextEdit and edit all of the options there. Below each of the options will be listed. Just paste the value after the equal sign on that line.

{% gist https://gist.github.com/ksmarty/47dda36c580688fe207c671fe457db37 %} 

* `DRONE_GITEA_SERVER`: The address of your Gitea server. 
Eg. https://git.example.com

* `DRONE_GITEA_CLIENT_ID`: The Client ID from step 4
Eg. f8cd8dfe-29f6–48f7–9c87–8b1bcec79dbe

* `DRONE_GITEA_CLIENT_SECRET`: The Client Secret from step 4
Eg. xpV0v74hKmDm5tulfR932TRZTVmkHWqCcZVJXG5CK4A=
P.s. Yes, it will end in an equal sign. No, this is not a mistake

* `DRONE_RPC_SECRET`: The shared secret generated in step 5
Eg. 2d2c5fc55c5991a8cc90f75e313d5670

* `DRONE_SERVER_HOST`: The domain of your drone server
Eg. drone.yourwebsite.com

* `DRONE_SERVER_PROTO`: Leave as http

Once you’ve edited all of the values, copy the command and paste it into your cloud console. Now you have a Drone CI server up and running!

## Creating a Runner

Runners are necessary to make pipelines function. Think of the Drone server as a marathon and a runner as a participant. Without participants, you can’t really have a marathon. A runner is the bit of code that actually does the work, the sever just gives the runner room to work.

Setting up a runner is just like setting up the server. First, we’ll pull the image off of DockerHub (This is where most docker images are hosted) and then we’ll run it with a configuration.

1. Pull the runner by running the following command in the cloud console:
`docker pull drone/drone-runner-docker:1`

1. The easiest way to do this next step is to copy the code below into Notepad or TextEdit and edit all of the options there. Below each of the options will be listed. Just paste the value after the equal sign on that line.

{% gist https://gist.github.com/ksmarty/e274169f8ad61663b0bc9f0b0cc49f31 %} 

* `DRONE_RPC_HOST`: The domain of your drone server
Eg. drone.yourwebsite.com

* `DRONE_RPC_SECRET`: The shared secret from awhile ago. This value should be the same as DRONE_RPC_SECRET from the server config

Now, simply copy the config and paste it into the cloud console and hit enter. Now, you’ve created your first runner!

## Conclusion

Now that everything is setup, you can head to your Drone server’s URL and start building pipelines. If you don’t know where to start, Drone’s documentation is where I’d suggest and can be found [here](https://docs.drone.io/quickstart/docker/). Enjoy and happy coding!