Building Automated CI server with Drone and Docker

08 Nov 2017 / by KhanhIceTea


Docker is great tool to management linux containers. It brings DevOps to next level, from development to production environment. And of course, before deploy anything to production, software should be tested carefully and automatically.

That's why Drone, a new lightweight CI server built-on top Go lang and Docker, will help us to resolve the testing problems in simple and fast way.


This guide will assume you already have Docker and Docker Compose tool. And of course, root permission ;)

Step 1 : Clone my example docker-compose here :

$ git clone
$ cd drone-ci
$ cp .env.example .env

Step 2 : Update your setting in .env file

Step 3 : Run drone via docker-compose

$ source .env
$ sudo docker-compose up -d

Step 4 : Go to your Drone url (remember use https url), then authorize with Github provider.


In example repo, I created a sample .drone.sample.yml file so you can follow the structure to create own file.

I will explain some basics here

    image: plugins/git
    depth: 5

    image: php:7
      - /bin/sh
      - /bin/sh app lib test
      - composer install -q --prefer-dist
      - test/db/import testdatabase root passwd testdb test.sql
      - php -d memory_limit=256M vendor/bin/phpunit --no-coverage --colors=never
    image: plugins/slack
    webhook: [your_slack_webhook_url]
    channel: deployment
    username: DroneCI
      status: success
    image: plugins/slack
    webhook: [your_slack_webhook_url]
    channel: bugs
    username: DroneCI
      status: failure
      branch: production

    image: mysql:5.7
    detach: true
      - MYSQL_DATABASE=testdb
      - MYSQL_ROOT_PASSWORD=passwd

This file consists 3 sections :

  • clone : To clone the source code and prepare for pipeline step. This section will be run first
  • services : Declare your docker services (databases, ip server) which source code connect to. This section will be run at sametime with pipeline (after clone)
  • pipeline : Testing pipe, where you put testing logic here.

In this pipeline, I made a example PHP testing through these steps :

  1. Check conflicts in code (grep for >>>> HEAD string)
  2. Run PHP linter in application codes
  3. Run Composer to install all dependencies
  4. Import testing database to mysql services (using testdatabase hostname to connect service)
  5. Run testing script via phpunit tool

Then, notify testing result via Slack channel ! ;)

A picture is worth a thousand words

Drone CI screenshot

Lets automate all the things !

Sound good ?