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:
- Introduction to DevOps
- Managing Team and Roles in DevOps
- Automated Notification and Testing
- 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:
- Build and run unit tests
- Deploy to stage environment
- Run integration tests
- Wait for manual approval
- Deploy to production if approved
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.
Now, let's set up a Continuous Delivery pipeline for this project.
Step 1: Add a new pipeline
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:
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.
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.
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.
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.
For more details, read Automated Notification and Testing with Buddy.
Here's what the pipeline should look like at this point:
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.
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.
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:
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.
Click 'Save this action' to save the action. Here's the final version of our 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.
The pipeline will wait for manual approval before deploying to the live site. Click on 'Approve' to finish executing the entire pipeline.
Once the deployment is successful, we will receive a success email notification.
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!