Using Drone in Walhall for CI/CD

Overview

Walhall 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 in Walhall?

As long as the repository you wish to connect to Walhall 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 Walhall's CI/CD pipeline. 
# Save this in the repository root. You don't have to change anything.
# All environment variables are created in Walhall as secrets.

pipeline:
# Walhall requires git tags to exactly match the image tags. 
# This step preserves the tags.
  preserve-git-tags:
    image: bash
    commands:
      # 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"
    when:
      event: [tag]

  # This step builds the image and pushes it to the registry when a tag is pushed.
  # Drone is configured to use the Walhall registry by default.
  build-docker-image-tag:
    image: plugins/docker
    registry:
      from_secret: DOCKER_REGISTRY
    repo:
      from_secret: DOCKER_REPO
    username:
      from_secret: DOCKER_USERNAME
    password:
      from_secret: DOCKER_PASSWORD
    insecure: true
    file: Dockerfile
    when:
      event: [tag]
      status: [success]

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

Drone’s auto-tag feature

Walhall 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