Continuous Delivery and Heroku with Buddy
Tags: devops, beginners, buddy, automation
Published: 2020-12-29 02:53:50

---
title: Continuous Delivery and Heroku with Buddy
published: true
date: 2020-09-11 03:32:28 UTC
tags: Devops,beginners,Buddy,automation
canonical_url: https://lo-victoria.com/continuous-delivery-and-heroku-with-buddy
---

Hello everyone! Welcome to the 5th article of [The DevOps Series with Buddy](https://hashnode.com/series/the-devops-series-with-buddy-ckbut97o9002nwus16xjmgt80). A series introducing beginner-friendly concepts in DevOps, discussing its importance and how to easily integrate it using [Buddy CI/CD](https://buddy.works?utm_source=devops_with_buddy&utm_medium=referral&utm_campaign=content_victoria_lo). 

If you are new to this series, please check out the previous articles:
1. [Introduction to DevOps](https://lo-victoria.com/introduction-to-devops-with-buddy)
2. [Managing Team and Roles in DevOps](https://lo-victoria.com/managing-team-and-roles-with-buddy)
3. [Automated Notification and Testing](https://lo-victoria.com/automated-notification-and-testing-with-buddy)
4. [Unit and Integration Testing](https://lo-victoria.com/continuous-integration-and-unit-testing-with-buddy)

In this article, we are going to learn how to deploy projects to Heroku and automate it for **Continuous Delivery** using Buddy. 

## What is Continuous Delivery?
Continuous Delivery is the practice of automating the steps to building a software until deployment-ready, where the code has been written and tested thoroughly. An additional **manual confirmation** will then trigger the release to the production server.

A typical Continuous Delivery pipeline consists of the following steps:
1. Build and run unit tests
2. Deploy to stage environment
3. Run integration tests
4. Wait for manual approval
5. Deploy to production if approved

![what-is-continuous-delivery.jpg](https://buddy.works/docs/static/articles/pipeline-examples/continuous-delivery-pipeline/continuous-delivery-pipeline-1.png)

A Continuous Delivery pipeline ensures that the code is consistently tested, allowing bugs or errors to be detected faster. It speeds up production cycles and automate repetitive tasks to reduce human errors that comes with manual work. Continuous Delivery ensures frictionless deployments, improve overall productivity within teams and allow faster manual approval for high quality releases to the end users.

## Continuous Delivery with Heroku
Getting started with Continuous Delivery is easy and intuitive when using Buddy CD/CI. Let's automate delivering a Node app to production-ready with Heroku and implementing for manual approval to deploy the app to production.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1596652513428/I0dwqO6uS.png?auto=format&q=60)

For this article, I will use my Tea API as an example, which is deployed at: https://tea-api-vic-lo.herokuapp.com/. For details on how to deploy a Node app to Heroku, please read this [article](https://lo-victoria.com/build-a-nodejs-api-for-beginners-6-deploying-the-api-finale-ckdl283wo042gz2s14etl796m).

Now, let's set up a Continuous Delivery pipeline for this project.

## Step 1: Add a new pipeline
If you haven't created a Buddy account, go to [buddy.works](https://buddy.works?utm_source=devops_with_buddy&utm_medium=referral&utm_campaign=content_victoria_lo) to set up an account and read the [first article](https://lo-victoria.com/introduction-to-devops-with-buddy-ckc86jas80080ups179d51nbg) to learn how to get started.

![Capture.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1596551631162/WlILUNsXH.png)

Once you have a project in Buddy's workspace, create a new pipeline that has the following configurations:

![](https://buddy.works/guides/images/deploy-to-heroku/heroku-4.png)

Trigger mode is set to **On push** so that the pipeline will execute every time changes are made to the project's repository. The trigger branch is where the pipeline will execute and for our project it is the **master** branch.

## Step 2: Add Unit Test action
Add a **Node** action to build and run tests with:
```
npm install
npm test
```

![node.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1598558897015/6Bsaejy-8.png)

> For more details on unit testing, refer to [Unit and Integration Testing](https://lo-victoria.com/unit-and-integration-testing-with-buddy-ckduyo7ke00amids1gjfqf729).

## Step 3: Deploy to Stage action
If all unit tests passed successfully, we will deploy the app to a staging environment for integration testing. To do this, run the following commands on your Heroku CLI:
```
heroku create --remote staging
git push staging master
heroku ps --remote staging
```
This will create a staging environment on your Heroku account. Then, back to Buddy, click on the **Heroku** action. 

You will need to allow Buddy to access the Heroku account in which the app is to be deployed at.

![3.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1597688336228/OIow7lXyZ.png)

Then, you will be taken back to the action where you can configure its settings. Check and make sure that the **Integration** and **Application** fields are correct.

![1.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1599759921463/uJ1QPO-cP.png)

> For more details on managing production and staging environment with Heroku, visit their site [here](https://devcenter.heroku.com/articles/multiple-environments#managing-staging-and-production-configurations).

## Step 4: Run Integration Tests
Next, we can add another **Node** action to run integration and other tests like cross-browser testing to make sure that the app is ready for deployment.

![run.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1599760060300/csB-V7Or_.png)

Once the app passed this stage, we should send an Email notification to the team to let them know that the app is ready to be approved for deployment to production.

![wait notification.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1598559607717/Cyym5f7TN.png)

> For more details, read [Automated Notification and Testing with Buddy](https://lo-victoria.com/automated-notification-and-testing-with-buddy-ckcw2779r01fx7is10taf6r3a).

Here's what the pipeline should look like at this point:
![halfway.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1598559635606/YI-y2qxx6.png)

## Step 5: Wait for Approval action
Add a **Wait for Approval** action to the pipeline so deployment must be manually approved by the specified members under the 'Permissions' settings. For this example, only **Administrators** are allowed to approve.

![approve.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1598559782207/kYvL3Ea5m.png)

## Step 6: Deploy to production server
Once Step 5 is approved, we can deploy the app. Add a **Heroku** action again.

Once again, check and make sure that the **Integration** and **Application** fields are correct. The app will be live at https://tea-api-vic-lo.herokuapp.com/.

![2.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1599759901488/gaGvtNjt1.png)

Then click **'Save this action'** to save and add the action into the pipeline.

## Step 7: Add Email Notification
Last but not least, we should have an action to send an email notification to the team when the app is successfully deployed to production so let's add an email notification action after our Heroku action.

We can configure a simple email that let the team know deployment is successful like so:

![5.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1597688785386/69buckqyh.png)

### Conditional Email Notification
We can add an email notification action under `ACTIONS RUN ON FAILURE` to send error logs to the team in the case where deployment fails. Let's add an email notification action under that section and configure a message like the image below. 

> You can add other notification methods such as Slack or MS Teams. Read more about it [here](https://buddy.works/docs/pipelines/notifications?utm_source=devops_with_buddy_docs&utm_medium=referral&utm_campaign=content_victoria_lo).

![7.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1597688951543/vqsnYK8el.png)

Click **'Save this action'** to save the action. Here's the final version of our pipeline:

![full CD pipeline.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1598560175701/0fznYzfe0.png)


## Run Pipeline!
Alright, our deployment pipeline is ready to be tested and executed. If there are no errors, we should see something like the image below.

![waiting.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1598566498214/7WMuph8s5.png)

The pipeline will wait for manual approval before deploying to the live site. Click on **'Approve'** to finish executing the entire pipeline.

![last.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1599760393426/h-EYmp8YM.png)

Once the deployment is successful, we will receive a success email notification.

![10.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1597689411004/nZfKKTiMi.png)

## Conclusion
In this article, we discussed what Continuous Delivery is and how you can set up a Continuous Delivery pipeline with [Buddy CI/CD](https://buddy.works?utm_source=devops_with_buddy&utm_medium=referral&utm_campaign=content_victoria_lo). I hope you have learned something new and insightful. 

With Buddy, there are countless useful [actions](https://buddy.works/actions?utm_source=devops_with_buddy_actions&utm_medium=referral&utm_campaign=content_victoria_lo) that you can add to easily build robust and complex Continuous Delivery pipelines for your projects. Please visit [buddy.works](https://buddy.works?utm_source=devops_with_buddy&utm_medium=referral&utm_campaign=content_victoria_lo) or read their documentation [here](https://buddy.works/docs?utm_source=devops_with_buddy_docs&utm_medium=referral&utm_campaign=content_victoria_lo) to learn more.

Thank you for reading. Please feel free to leave a like or share any thoughts in the comments below. In the final part of this series, we will be discussing Continuous Deployment and how to fully automate your pipeline. Stay tuned and cheers!