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 Git Provider. Start by clicking on the
Connect Git Provider button. You will then be prompted to log in with your GitHub account.
Step 3: Activate a repository
Once you've logged in to your GitHub account, you'll be able to view all your 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 and select the required Machine Type.
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.
Now, in order to setup our CI/CD pipeline, we'll need to create a special file in our repository root directory called
This file can be generated from the Patr UI, in the
Pipeline tab of the repository.
patr.yml file is shown below.
kind: pipeline 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 name: Default
Then, we start by defining the steps in the
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
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.