Skip to content

Drone

In this tutorial, we'll create a project using Drone (by Harness) as the automation system and deploybot to manage deploys.

When code is pushed to GitHub in a Pull Request or merged, Drone will run a build/test pipeline to run unit tests and build a Go binary. Then we'll use deploybot to trigger a Drone deploy pipeline, step through deploy environments, or auto-deploy after tests pass on a branch.

Requirements

GitHub

Create a GitHub repository for your project. You may wish to git clone or download deploybot-app/drone-example to get started.

git clone [email protected]:deploybot-app/drone-example.git

A project may be anything you wish to deploy in some way. If you need some starter code, the example shows a tiny Go program and test.

Drone

Login to your Drone server's dashboard and find the GitHub repository for your project. Check that Drone has permission to access the repo or click "Sync" if it doesn't appear.

Drone sync and find repo

Activate Drone on the repository and set the Drone config file location (e.g. .drone.yml).

Drone activate repo

Build / Test

Project build or test pipelines run language-specific unit tests, build binaries or container images, publish artifacts, upload packages, or push container images to a registry. With Drone, these test or build pipelines are triggered when code is pushed to GitHub.

Info

If your project already defines build or test pipelines, skip this section.

Create a new Pipeline for running a build or test.

# .drone.yml
kind: pipeline
type: kubernetes
name: golang-image
trigger:
  event:
    - push
steps:
  - name: build
    image: docker.io/golang:1.18.3-alpine3.15
    commands:
    - go version
    - go test ./...

The example repo defines a golang-image pipeline that starts a Kubernetes Pod, clones code, and runs Go tests whenever code is pushed to Github.

Deployment

A deployment is a process for rolling out a change to a target environment. A Drone deploy might update a binary, apply Kubernetes manifests, sync files to a CDN, upload a package, tag a release, ring a bell, or anything you can define in a Drone pipeline.

Add a new pipeline for performing a deployment. Pipelines can be added to the Drone config file (e.g. .drone.yml) using a yaml --- separator from other pipelines.

# .drone.yml
...

---
kind: pipeline
type: kubernetes
name: deploy
trigger:
  event:
    - promote
steps:
  - name: plan
    image: docker.io/hashicorp/terraform:1.2.2
    commands:
      - echo "Deploying $DRONE_REPO_NAME at $DRONE_COMMIT_SHA to $DRONE_DEPLOY_TO"

The example repo defines a deploy pipeline that starts a Kubernetes Pod, clones code, and prints a message whenever a GitHub Deployment is created.

Drone provides the promote trigger event to define that a pipeline should execute when a GitHub Deployment event is received.

trigger:
  event:
    - promote

Drone also provides target filters to run a pipeline only for deploys to specific environments if needed.

trigger:
  target:
    - development
    - staging

Drone supports many environment variables that can be used in pipelines. A few that are especially relevant for deployments are:

  • DRONE_REPO_NAME - name of the repository (drone-example)
  • DRONE_COMMIT_SHA - Git SHA1 hash to deploy (e.g. 83a20ec058e2fb00e7fa4558c4c6e81e2dcf253d)
  • DRONE_DEPLOY_TO - name of the target deployment environment (e.g. production)

Deploybot

Add a deploybot configuration file to your project at .github/deploybot.yaml on the default branch. Define the GitHub Environments that should be deployable (up to 4).

# .github/deploybot.yaml
deployments:
- name: development
- name: staging
- name: production

Login to deploybot. Find your project among your personal repos or organization repos.

Deploybot User or Org Repos

Manual Deploys

The commits timeline shows recent commits on the default or feature branches, while the deploy steps show deployable GitHub Environments.

Manual Deploys

Use the Deploy buttons to create a GitHub Deployment of a commit to an environment. Each GitHub Deployment notifies GitHub that a deploy should be performed and triggers Drone to run the deploy pipeline.

Automated Deploys

Deploybot can be configured to deploy to environments automatically.

For example, set on_push: true to create a GitHub Deployment when a commit is pushed to the default branch, after it passes tests.

# .github/deploybot.yaml
deployments:
- name: development
  on_push: true

- name: production
  # still manual

Auto-deploys by Deploybot

Note

More advanced configuration settings are planned.

History

View recent deployment history across an organization or for an individual repository.

Organizaiton overview

Drone itself provides visualizations for deployment history for individual repos.

Drone history