Continuous Delivery and Heroku with Buddy

Continuous Delivery and Heroku with Buddy

Hello everyone! Welcome to the 5th article of The DevOps Series with Buddy. A series introducing beginner-friendly concepts in DevOps, discussing its importance and how to easily integrate it using Buddy CI/CD.

If you are new to this series, please check out the previous articles:

  1. Introduction to DevOps
  2. Managing Team and Roles in DevOps
  3. Automated Notification and Testing
  4. Unit and Integration Testing

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

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.

For this article, I will use my Tea API as an example, which is deployed at: tea-api-vic-lo.herokuapp.com. For details on how to deploy a Node app to Heroku, please read this article.

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 to set up an account and read the first article to learn how to get started.

Capture.PNG

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

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

For more details on unit testing, refer to Unit and Integration Testing.

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

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

For more details on managing production and staging environment with Heroku, visit their site here.

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

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

For more details, read Automated Notification and Testing with Buddy.

Here's what the pipeline should look like at this point: halfway.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

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 tea-api-vic-lo.herokuapp.com.

2.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

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.

7.PNG

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

full CD pipeline.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

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

last.PNG

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

10.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. I hope you have learned something new and insightful.

With Buddy, there are countless useful actions that you can add to easily build robust and complex Continuous Delivery pipelines for your projects. Please visit buddy.works or read their documentation here 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!

Did you find this article valuable?

Support Articles by Victoria Lo by becoming a sponsor. Any amount is appreciated!

ย