Experiment with drone CI server & drone docker runner with github enterprise in minutes

Simon Zhao
4 min readDec 12, 2020

--

Photo by Juan Cruz Mountford on Unsplash

In this article, I would introduce drone , a lightweight continuous integration(CI) tool for developers. I would demo how to :

  • Install drone server
  • Install drone docker runner
  • Connect drone server and github enterprise
  • Develop a pipeline in drone to build your docker image and push the image to a private docker registry

What is Drone?

Drone is a self-service Continuous Integration platform for busy development teams. It integrates seamlessly with multiple source code management systems, including GitHub, GitHub Enterprise, Bitbucket, and GitLab. It can work with many languages, databases and services that runs inside a Docker container.

You can do continuous integration without jenkins, just use drone as an alternative method to build your app.

How to Install Drone Server with github enterprise edition?

  1. Create oauth in github enterprise

Open your github enterprise web interface , and click to create an oauth web app , obtain these tokens:

2. create shared secret

We must create a shared secret to be used by drone server and drone runner, just create it as follows:

➜ ~ openssl rand -hex 16
0a29dff76cc62f0de32cf30ca81f21e6

3. Start drone server by using the following command:

Let’s execute the above script:

[root@k8s-test-2 ~]# docker run \
> --volume=/var/lib/drone:/data \
> --env=DRONE_GITHUB_SERVER=https://10.21.121.4 \
> --env=DRONE_GITHUB_CLIENT_ID=5d7f4594c051a94213e6 \
> --env=DRONE_GITHUB_CLIENT_SECRET=14fc4d1ef552c83bca345b \
> --env=DRONE_RPC_SECRET=0a29dff76cc62f0de32cf30ca81f21e6 \
> --env=DRONE_SERVER_HOST=192.168.1.2:28089 \
> --env=DRONE_SERVER_PROTO=http \
> --publish=28089:80 \
> --publish=443:443 \
> --restart=always \
> --detach=true \
> --name=drone \
> 192.168.1.2:8443/bswen/drone:1
Unable to find image '192.168.1.2:8443/bswen/drone:1' locally
1: Pulling from bswen/drone
cbdbe7a5bc2a: Pull complete
b811a68a9265: Pull complete
90bb4f4fa574: Pull complete
e17f94d28fae: Pull complete
Digest: sha256:659667378409777a525c7712d308ad6de58b69cc3c7d54d5b684dd
Status: Downloaded newer image for 192.168.1.2:8443/bswen/drone:1
612ea3fb36a63134e648ae90cb55d2b0eddf2ecf445691de1562631c3f961486
[root@k8s-test-112 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
612ea3fb36a6 192.168.1.2:8443/bswen/drone:1 "/bin/drone-server" 4 seconds ago Up 3 seconds 80/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:80->28089/tcp drone

4. view the logs of drone server:

[root@k8s-test-112 ~]# docker logs -f 612ea3fb36a6
{"level":"info","msg":"main: internal scheduler enabled","time":"2020-12-11T05:32:57Z"}
{"acme":false,"host":"192.168.1.2:28089","level":"info","msg":"starting the http server","port":":80","proto":"http","time":"2020-12-11T05:32:57Z","url":"http://192.168.1.2:28089"}
{"interval":"30m0s","level":"info","msg":"starting the cron scheduler","time":"2020-12-11T05:32:57Z"}
{"interval":"24h0m0s","level":"info","msg":"starting the zombie build reaper","time":"2020-12-11T05:32:57Z"}

Install drone runner

Drone runners poll the server for workloads to execute. There are different types of runners optimized for different use cases and runtime environments. You can install one or many runners, of one or many types.

The ci process is as follows:

  • Developer push the code to github or github enterprise server
  • If the repository is correctly configured , it would send a webhook call to the drone server
  • Drone server would got the notification from github server
  • Drone runners poll the drone server for jobs to execute, if it finds one, it would execute the job in its environment,e.g. docker environment

Let’s start a drone runner docker with this command:

View the docker containers of drones:

[root@k8s-test-112 ~]# docker ps|grep drone
5d247f164220 192.168.1.2:8443/bswen/drone-runner-docker:1 "/bin/drone-runner-d…" About a minute ago Up About a minute 0.0.0.0:3000->3000/tcp runner
612ea3fb36a6 192.168.1.2:8443/bswen/drone:1 "/bin/drone-server" 9 minutes ago Up 9 minutes 80/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:80->28089/tcp drone
[root@k8s-test-112 ~]#

View the logs of the drone-runner-docker:

time="2020-12-11T05:47:35Z" level=info msg="successfully pinged the remote server"
time="2020-12-11T05:47:35Z" level=info msg="polling the remote server" arch=amd64 capacity=2 endpoint="http://192.168.1.2:28089" kind=pipeline os=linux type=docker

Access the drone runner docker dashboard

Navigate to http://192.168.1.2:3000 , input the username and password, then you would see this:

Develop your first drone pipeline

A drone pipeline is a workflow that would automate your build process, just as jenkins pipeline, Let’s create our drone pineline as follows:

Create a file named .drone.yml in the root directory of your git repository with the following content:

Then you would see this in the drone server dashboard:

Conclusion

Why we choose drone ,not jenkins to build the code? I think the key reason is that drone is much lighter than jenkins, which is most powerful ci/cd tool in the world. After following the guide, you would find that drone ci is very easy to learn, and the pineline yaml is easy to write, and it can be started in docker, all well done!

--

--

Simon Zhao
Simon Zhao

Written by Simon Zhao

Security techie, developer, technology manager, software person and app-stuff doer..

No responses yet