Configuring a Front-End Project for Continuous Integration with Drone

Activating the Repo in Drone

  1. Login to Vokal's Drone instance here: https://dronev4.vokal.io/
  2. Find your Github repo, and click it
  3. If this repo hasn't been activated for Drone, you will see the message "This repository is not yet activated." Click Activate Now.

Create Your Project's .drone.yml File

In the root of your repo, create a file called .drone.yml. Use the example below to create a drone config in this new file.

build:

  # The step below executes when new commits are pushed to any branch
  # other than master, e.g. when a feature PR is opened, when
  # new commits are pushed to that PR, or when that PR is merged
  # to develop
  staging:
    when:
      branches:
        exclude: master
    image: node
    commands:
      - yarn install
      - yarn run build:staging
      - yarn test

  # The step below only executes when new commits are pushed to master,
  # which should only occur when a release or hotfix branch is merged
  # to master
  prod:
    when:
      branch: master
    image: node
    commands:
      - yarn install
      - yarn run build
      - yarn test

# Top level steps (like build and publish) execute sequentially, by
# design. This ensures that if the build or tests fail, the publish step
# will not run, preventing a broken build from being distributed
publish:

  # The step below only executes when new commits are pushed to develop,
  # e.g. when a feature branch is merged successfully. It should contain
  # the task that will deploy your app to the staging environment.
  s3_sync:
    when:
      branch: develop
    acl: public-read
    region: "us-east-1"
    bucket: "my-staging-bucket" # Replace this with the name of your bucket
    access_key: $$awsAccessKey
    secret_key: $$awsSecretKey
    source: build
    target: /
    delete: true

  # The step below only executes when new commits are pushed to master,
  # e.g. when a release branch is merged successfully. It should contain
  # tasks that will deploy your app to the production environment.
  s3_sync:
    when:
      branch: master
    acl: public-read
    region: "us-east-1"
    bucket: "my-production-bucket" # Replace this with the name of your bucket
    access_key: $$awsAccessKey
    secret_key: $$awsSecretKey
    source: build
    target: /
    delete: true

Some things to note:

If you have any other questions about Drone config files, ask a senior dev, or look through the docs.

Passing the Environment Variables to .drone.yml

  1. Go back to our Drone instance and find your repo.
  2. Click the Secrets tab in the upper right corner.
  3. In the text box, enter the environment variables you reference in your .drone.yml file with their values, using yaml syntax. (Note: You'll probably be doing this with AWS credentials most commonly. If you don't know how to find yours, read this guide.) Here's an example of what you'll be typing into this field:
environment:
  awsAccessKey: AAAAAAAAAAAAAAA
  awsSecretKey: asdf7782j2k3l;asdf/abyqu378123;ajsdbn;alwer
  1. Click Generate to encrypt your secret variables.
  2. Copy the output and paste it into a new .drone.sec file in the root of your repo.

And that's it! Congratulations: You've successfully configured your repo for Continuous Integration and Continuous Delivery with Drone. The next time you open a PR, Github will display a the progress of Drone executing the steps in this config file. You can go to Drone at any time to view current and past builds, and their console output.