Setting Up Drone CI

2 minute read

Drone

Setting Up Drone CI

Drone CI is an open-source and self-hostable automatic building system. It allows you to focus on programming by automatically building your code and also even publishing release binaries. There are also many available plugins that allows it to push binaries to a server over rsync, to publish latest release to a git repo, and even notifications to SLACK.

There are two Drone services:

Linux installation:

  1. Make sure Docker and Docker Compose are installed and setup. Guide

  2. Create a directory for drone

mkdir -p /home/(username)/docker/drone

  1. Read setup guides
  1. Configure docker-compose.yml for Drone server.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#docker-compose.yml
version: "3"
services:
  drone:
    container_name: drone
    image: drone/drone:latest
    environment:
      - DRONE_GITEA_SERVER=										#change to DRONE_GITset to url of gitea/gitea
      - DRONE_GITEA_CLIENT_ID=                                  #set to client id from github/gitea
      - DRONE_GITEA_CLIENT_SECRET=								#set to client secret from github/gitea
      - DRONE_RPC_SECRET=										#generate a key $openssl rand -base64 (length)	
      - DRONE_SERVER_HOST=										#set domain name
      - DRONE_SERVER_PROTO=https
      - DRONE_USER_CREATE=username:(username),admin:true 		#create user that matches git/gitea username
      - DRONE_USER_FILTER=(username),admin						#create user that matches git/gitea username
      - DRONE_AGENTS_ENABLED=true
      - DRONE_DATABASE_DRIVER=postgres
      - DRONE_DATABASE_DATASOURCE=postgres://drone:(password)@drone_db:5432/drone?sslmode=disable	#remote (password) and insert password that matches POSTGRES_PASSWORD
#    labels:								                    #optional Traefik config
#      - "traefik.enable=true"									#remote (domain) and insert url
#      - "traefik.http.routers.drone.rule=Host(`(domain)`)"
#      - "traefik.http.routers.drone.tls=true"								
#      - "traefik.http.routers.drone.tls.certresolver=letsencrypt"
    restart: always
    volumes:
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    networks:
      - web
      - drone

  drone_db:
    container_name: drone_db
    image: postgres:latest
    environment:
      - POSTGRES_USER=drone
      - POSTGRES_PASSWORD=          #set password
      - POSTGRES_DB=drone
#    labels:			            #optional Traefik config
#      - "traefik.enable=false"
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - drone_db:/var/lib/postgresql/data
    networks:
      - drone
    restart: always

volumes:
  drone_db:

networks:
  drone: 
  1. Configure docker-compose.yml for a Drone runner on same or different host.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#docker-compose.yml
version: "3"
services: 
  drone-runner:
    image: drone/drone-runner-docker:latest
    container_name: drone-runner
    ports: 
      - 3000:3000
    environment:
      - DRONE_RPC_PROTO=https					#change to http/https
      - DRONE_RPC_HOST=drone.magnatox.com			#drone url
      - DRONE_RPC_SECRET=4862fe3bd5703c5686f1586996a39f00	#copy secret generated from previous step
      - DRONE_RUNNER_CAPACITY=2					#divides total host resources into n number of jobs (2 is a good starting point for 2+ core systems)
      - DRONE_RUNNER_NAME=					#set drone runner url
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock		#give drone runner access to docker 
    restart: always
  1. On Drone server system start server.

docker-compose up -d

  1. On Drone runner system start runner.

docker-compose up -d

  1. Make sure to follow the Guides and configure website redirect.

  2. Login to Drone server url and you will be prompted with a authentication request.

  3. Setup will be complete with all repositories displayed.

  4. Read Quickstart to learn more about creating pipelines in .drone.yml files.