Using Drone for CI


The Humanitec platform comes with a hosted instance of Drone that can be used to run Continuous Integration (CI) for modules you include in your apps. This page explains how it works.

What is Drone?

Drone is an open-source, container-native CI pipeline engine. It is particularly well suited for building CI pipelines for containerized apps. It can be configured to build the images necessary for running your app, run tests, and place the built images in your registry.

You can find out more on the Drone website.

How do I use it with the Humanitec platform?

As long as the repository you wish to connect to the platform contains a Dockerfile, all you have to do is add a .drone.yml file in the root. Here is a minimal file you can use straight away:

# .drone.yml - Sample file for connecting your module to the Humanitec platform's CI/CD pipeline. 
# Save this in the repository root. You don't have to change anything.
# All environment variables are created in the Humanitec platform as secrets.

# The Humanitec platform requires git tags to exactly match the image tags. 
# This step preserves the tags.
    image: bash
      # If the commit reference is a tag, then Drone will write the tag to the .tags file
      - bash -c "[[ \"${DRONE_COMMIT_REF}\" == \"refs/tags/\"* ]] && echo \"${DRONE_COMMIT_REF#refs/tags/}\" > .tags"
      event: [tag]

  # This step builds the module's Docker image and pushes it to the registry when a tag is pushed.
  # Drone is configured to use the Humanitec registry by default.
    image: plugins/docker
      from_secret: DOCKER_REGISTRY
      from_secret: DOCKER_REPO
      from_secret: DOCKER_USERNAME
      from_secret: DOCKER_PASSWORD
    insecure: true
    file: Dockerfile
      event: [tag]
      status: [success]

After you add your Drone file, you must push a tag in the repository.

Drone’s auto-tag feature

The platform identifies images in the registry by matching the tags in git to the tags in the registry.

Drone includes an auto-tag feature, but it is very opinionated about how tags are generated. If you wish to use this feature, then you must write your git tags in the X.X.X format (where X denotes a numeral). Example: 1.3.12