Deploying a self-hosted Android Ci Solution with Drone & Gogs (Pt.2 - Drone)

  • Pre-flights checks:

  • You need a sub-domain for your Drone server. You can create it in Cloudflare under your root domain, or as a normal vanilla sub-domain with your preferred registrar. Something like

  • Docker is installed.

  • Docker Compose is installed.

Let's begin:


Drone CI Config:

Our Working directory is in /etc/drone. Create this using the following command:

sudo mkdir /etc/drone

cd into it:

cd /etc/drone

Set up your initial Drone server config with the following:

sudo vi docker-compose.yml

Enter the below information:

#initial sever config for docker compose file 

version: '3'

    image: drone/drone:0.8.4

      - /var/lib/drone:/var/lib/drone/
    restart: always
      - /etc/drone/server.env

    image: drone/agent:0.8.4
    command: agent
    restart: always
      - drone-server
      - /var/run/docker.sock:/var/run/docker.sock
      - /etc/drone/agent.env

Env Files

The above referenced env files will have the configs for drone:

Create your server.env file:

sudo vi server.env

Enter the below information

  • Server.env:
#Service settings
DRONE_SECRET=<< your random char drone secret>
DRONE_HOST=<your drone server sub-domain url>
#Registration settings:
DRONE_OPEN=false # you don't want random strangers to register
DRONE_GOGS=true # enables gogs support
DRONE_GOGS_URL=<your existing gogs url>
DRONE_GOGS_GIT_PASSWORD=<configured gogs password>

DRONE_GOGS_PRIVATE=true has to be set if this is a gogs server that doesn't allow cloning anonymously. We need this here or our authentication will fail on our builds when Drone tries to clone this, often with the following:

Initialized empty Git repository in /drone/src/droneurl/path/torepo/.git/
+ git remote add origin https://droneurl/path/torepo/.git/
+ git fetch --no-tags origin +refs/heads/master:
fatal: could not read Username for 'https://droneurl/path/torepo/.git/': No such device or address
exit status 128

We don't want this!

create your agent env file:

sudo vi agent.env

  • Agent.env:
#Agent Info
DRONE_SECRET=<drone secret>

We can test this works by running docker-compose up to make sure everything starts up successfully:

/usr/local/bin/docker-compose -f /etc/drone/docker-compose.yml up

You can just cancel the running process by pressing the ctrl+c combination on your keyboard.

Next, we want our Drone server to be started as a service even when the server starts and at all times. This way you don't have to manually invoke the process each time:

  • Create your unit File:

sudo vi /etc/systemd/system/droneci.service

Then enter the following:

# This way we can have it start when our server run as a service:

Description=Drone Server
After=docker.service nginx.service # we need this to start after docker and nginx have started

ExecStart=/usr/local/bin/docker-compose -f /etc/drone/docker-compose.yml up #start cmd
ExecStop=/usr/local/bin/docker-compose -f /etc/drone/docker-compose.yml #stop cmd


Start the service by running the following command:

sudo systemctl start drone.service

Then check the status of your service:

sudo systemctl status drone.service

If it start's successfully, then it's safe to enable it as a service on system boot:

sudo systemctl enable drone.service

The console should output info saying that it's created the necessary symlinks for the service to start on boot.

If you need any further info regarding Drone, you can check out their official docs here

You can hop onto setting up Nginx with Part 3

Vusi Moyo

Some guy that found code on the internet and is treating it like play dough

Read More