Skip to content

CI / CD

We will now see how to build a CI/CD pipeline on Patr.

Step 1: Navigate to CI/CD

Navigate to the CI/CD section on Patr.

Step 2: Connect a GitHub account

Connect your GitHub Repository. Start by clicking on the Connect GitHub button. You will then be prompted to log in with your GitHub account. CI-GitHub

Step 3: Activate a repository

Once you've logged in to your GitHub account, you'll be able to view all your GitHub respositories. GitHub-Repositories

Let's start with selecting the repository we want to setup builds for, and click on it.

Once opened, you'll see an Activate button. Click on it to activate the repository.

Activate Repository

Step 4: Setup your CI Pipeline

Once activated, any new commits pushed to the repository will now be built by the Patr CI/CD pipeline.

Activated Repository

Now, in order to setup our CI/CD pipeline, we'll need to create a special file in our repository root directory called .drone.yml.

You can read more about the pipeline configuration steps here: Drone CI/CD.

A sample .drone.yml file is shown below.

kind: pipeline
type: docker
name: Default

steps:
  - name: "Install Dependencies"
    image: node:latest
    commands:
      - npm ci

  - name: "Run tests"
    image: node:latest
    commands:
      - npm run test

  - name: "Build"
    image: node:latest
    commands:
      - npm run build
    environment:
      NODE_ENV: "production"

  - name: "Publish on Patr"
    image: node:latest
    commands:
      - npm run publish

Let's break down the file above into parts.

First, we have the following:

kind: pipeline
type: docker
name: Default

These are used to mention that we're configuring a docker pipeline. While there are other options available, Patr only supports Docker Runners for now. If you're unsure of what this does, you can leave it as is.

Then, we start by defining the steps in the steps: part.

Each step defined in the pipeline is a docker container that gets executed. For each step, the CI pipeline will create a new docker container, mount your code in the current working directory as a volume, and execute the commands defined in the commands: part.

This way, you can execute any command in the docker container that is required to build your application.

Additionally, because each step is a docker container, you can also mention certain steps of your application to deploy your website upon successful completion. Each step will only execute if the previous step has exited with a success status code (a zero status code), so your applications will only be deployed if all previous steps have completed successfully.

You can also use these steps to get alerts and notifications in case your build fails.