{{announcement.body}}
{{announcement.title}}

Continuous Deployment Shouldn't Be Hard

DZone 's Guide to

Continuous Deployment Shouldn't Be Hard

Imagine if there were no more nights and weekends spent packaging builds and manually deploying across servers!

· DevOps Zone ·
Free Resource

Introduction

Over the past decade, continuous integration (CI) and continuous delivery (CD) have become staples of the software development lifecycle. CI automates the process of merging code and checking for basic regressions and code quality issues, relieving some of the code review burdens on your dev team. CD and automated deployments eliminate the overhead involved each time a new feature or a hotfix needs to get deployed. 

Imagine if there were no more nights and weekends spent packaging builds and manually deploying across servers! A functional CI/CD setup makes it significantly easier to have a truly agile workflow, as you can deploy as frequently as you want to.

However, CD, in particular, can be difficult to set up, oftentimes involving learning a whole new set of skills involving Dockerfiles, YAML, and the idiosyncrasies of each app and environment. Especially for smaller teams, these complexities make the idea of having automated deployments just a dream.

Continuous deployment doesn’t need to be this hard to set up.

As a full-stack developer and consultant who often helps dev teams to increase the value they deliver each sprint, when Heroku Flow came onto my radar I knew it was time to take a closer look. Could this be the simple, straightforward solution I’d been looking for?

What Is Heroku Flow?

Heroku Flow is the umbrella for a few different Heroku products which work together to provide a full CI/CD suite of tools. For CI, there’s Heroku CI. For CD, there is Heroku Pipelines, which allows you to specify a group of environments within which to promote builds, and Heroku Review Apps, which give you on-demand builds of each pull request. Bringing it all together is the GitHub Integration, which allows the process to be automatically triggered simply by pushing to your default branch.

Let’s set up a sample application and see what it takes. Do note that Heroku Review Apps is currently only available with the GitHub Integration.

How to Set Up Heroku Flow

First, you will need an application to experiment with. If you’re just trying things out, feel free to fork my sample application. It’s a basic Next.js application with a simple unit test added.

If you are adding your own Next.js application, do note that you will need to add a PORT arg to the start command, as below:

From there, sign up for a Heroku account and let’s get started!

Heroku Pipeline

In your Heroku dashboard, create a new pipeline:

Give it any name you like.

You can either connect it to GitHub on creation, or you can do so after creating the pipeline:

Machine generated alternative text: heroku-fiow-test-pipeline Pipeline Tests Access Settings o Heroku Cl. Learn more. STAGING + Add app Staging apps can be used to preview code changes and features before being deployed to productiom Add app Connect this pipeline to GitHub to enable additional features such as review apps, automatic deploys, and Dismiss Connect to GitHub PRODUCTION + Add app Production apps run your customer facing code. We recommend promoting your code from a staging app that has been tested. Add app

And the pipeline is created! Let's keep moving.

Heroku Review Apps

Let’s turn on Review Apps:

You’ll see a number of options. As a default configuration, I recommend the following:

Wow, that was easy too! Just a couple more steps to go.

Adding Environments and CI

With the pipeline created, now we need to add some apps. I’ll add staging and production environments:

Do this twice, once for each environment. You should end up with something like the screenshot below:

Pipeline Tests Access Settings REVIEW APPS Configure + New app This pipeline is using the new Review Apps Give us feedback There are no open pull requests on henryjin3/ heroku-now-test-aup STAGING + Add app heroku-flow-test-staging PRODUCTION + Add app heroku-fiowtest-prod Promote to production Open app Open app

I also recommend setting up automatic deployments to your first environment. For me, it’s Staging:

STAGING + Add app heroku-fiow-test-staging Open app Promote to production Configure automatic deploys.. Deploy a branch... Move app to development Move app to production X Remove from pipeline
Configure automatic deployment for heroku-flow-test-staging Enable automatic deploys from GitHub Every push to the branch you specify here will deploy a new version of this app. Deploys happen automatically: be sure that this branch is always in a deployable state and any tests have passed before you push. Learn more. Choose a branch to deploy V master Wait for CI to pass before deploy Only enable this option if you have a Continuous Integration service configured on your repo. Cancel Enable Automatic Deploys

 

Finally, let’s turn on CI as well. One more click and we’re done.

Disable Review Apps for this pipeline Heroku CI Configure tests using Heroku CI Enable Heroku CI test runs Disable Enable this feature for Heroku CI to run your tests automatically after every push to the GitHub repository connected to this pipeline. A configured appjson may be required. Learn more. Each pipeline with Heroku CI enabled is charged SIO/month_ Charges for dyno and add- on usage from test runs are prorated to the second. All charges are billed to the selected pipeline owner. Enable Heroku CI

That’s it! What, you don’t believe me? Don’t believe that it could really all be working that easily? Well, let’s test it and see, shall we?

Testing Heroku Flow

Ready to try everything out? Create a pull request in your repo. For me, I decided to create a PR around adding unit tests. You should see something like this once you’ve created your PR in GitHub:

Initial jest add henryjin3 wants to merge 1 commit into master from addtesting Open Conversation 0 Commits 1 a. Checks 0 Files changed 10 henryjin3 commented 10 seconds ago No description pro vided. Initial jest add -L Add more commits by pushing to the addtesting branch on henryjin3/heroku-flow-test-app. Some checks haven't completed yet 1 pending check continuous-integration/heroku Pending — running tests This branch has no conflicts with the base branch Merging can be performed automatically. Owner • baaclfl Hide all checks Details Merge pull request You can also open this in GitHub Desktop or view command line instructions.

Clicking "Details" takes you to Heroku’s site, where you can see the CI's status.

Pipeline Tests Access Settings V All branches C #2 Initial jest add @ Tests passed #1 Initial add Tests passed O NewTest addtest ing Today at 3:11 PM addtest ing Today at 3:10 PM V #2 passed after 1m 32s addtesting Ibaaclfll Initial jest add TEST SETUP SUCCEEDED TESTS SUCCEEDED o Running Vode.js buildpack tests. Run Again J Todayat3:11PM > heroku-flcm-test-app@e.l.e test 'app jest PASS tests/ index. test. js (S. 912 s) v' renders without crashing (3e8 ms) Test Suites: 1 passed, 1 total Tests : Snapshots: 1 passed, 1 total e total 7.884 s Ran all test suites. o Vode.js buildpack tests completed successfully Tests fi nished

Alongside the CI (or after, depending on your settings), deployment of the review app will occur as well. Note: if you selected the option to deploy the review app after CI, but you have no tests, it won't deploy. So make sure you have at least one test!

Initial jest add Open henryjin3 wants to merge 1 commit into master from addtesting Conversation 0 Commits 1 a. Checks 0 Files changed 10 Owner henryjin3 commented 3 minutes ago No description pro vided. Initial jest add henryjin3 deployed to heroku-flow-addtesting-hjljqfq 1 minute ago baaclfl View deployment Add more commits by pushing to the addtesting branch on henryjin3/heroku-flow-test-app. This branch was successfully deployed 1 active deployment heroku -flow-addtesting - hjljqfq All checks have passed 1 successful check baaclflb Deployed 1 minute ago by henryjin3 Hide environments View deployment Show all checks

Click “View deployment”, and you will be taken to your review app. If you’re using my sample application, you’ll see the following:

Your test Next.jy app is up and running! Any questions? Check out my website at

Looking good. Let’s go ahead and merge the PR. Then, you can check out whichever environment you set up automatic deployments for. In my case, it’s the Staging environment:

heroku-fiow-test-pipeline Pipeline Tests Access Settings STAGING + Add app heroku-fiow-test-staging Auto deploys master • O henryjin3/heroku-fIow-test-app PRODUCTION + Add app heroku-fiow-test-prod REVIEW APPS Configure + New app This pipeline is using the new Review Apps Give us feedback #1 Initial jest add Create review app Promote to production Open app

See that yellow circle? Once it’s green, you’re ready to go:

STAGING + Add app heroku-fiow-test-staging Auto deploys master 48S66fd1 Deployed today at 3:28 PM Promote to production Open app

Click “Open app”, and make sure everything looks good. Ready to go to production? Just click “Promote to production”.

Promote heroku-fiow-test-staging Auto deploys master 48S66fd1 Deployed today at 3:28 PM TO PRODUCTION heroku-fiow-test-prod A promotion to production will occur without rebuilding the source slug Release phase will still be run. Leam more Cancel Promote

Be ready, once you click “Promote” it will be there in an instant.

STAGING + Add app heroku-fiow-test-staging Auto deploys master 48S66fd1 Deployed today at 3:28 PM No changes to promote Open app PRODUCTION + Add app heroku-fiow-test-prod 48S66fd1 Deployed just now @ Released Open app

That’s it! We just took a code change all the way from the PR stage into production. Let’s zoom out and think about this in the context of some other competing products.

Let's Talk DevOps

My DevOps journey started with Azure DevOps–although, at that time, it was called Microsoft Application Lifecycle Management. What is now Azure Pipelines used to be Microsoft Release Management, and that was the tool (along with on-premises TFS, Team Build, and Microsoft Test Manager) which formed the center of our CI/CD efforts? At the time, I was part of a small company which lacked standardized process and procedures, and so with a couple of others, I formed an internal DevOps team to promote CI/CD across all of our company’s projects. That said, each project had a different setup; some had CI, some had CD, a few had CD only for dev/test, etc. In general, we just tried to do something under the assumption that something was better than nothing.

Since that time, I’ve gained experience both with Azure DevOps as well as GitHub Actions. Both of these solutions are significant improvements over the older Microsoft tools, and it's easier than ever to get a basic CI/CD setup going for your team. However, Azure DevOps is still a somewhat strange blend of the legacy Release Management as well as the new YAML-based workflow setup, and GitHub Actions is just new enough that sometimes there isn’t a pre-built action to do exactly what you need. Both of these issues make it so that you need to spend more time and resources setting up and maintaining your CI/CD setup, increasing overhead costs. 

I’ve also had the opportunity recently to use Netlify for my personal site, and with just a few clicks my CI/CD was up and running, review apps, and all. That left me really wanting to find something similar for business use which would handle more complex use cases beyond a JAMStack app.

I’m happy to find that Heroku is offering a similar, no-hassle CI/CD experience, but with the additional flexibility of the rest of the Heroku platform. It’s hard to emphasize just how easy this was. I’m sure there will be complications later on, as there are in almost any DevOps task, but I generally find with DevOps that ease-of-use, in the beginning, continues to pay dividends even with more complex scenarios.

As for review apps, GitHub Actions doesn’t have it built-in at all. Azure DevOps is getting there, but this requires you to also set up and maintain Azure Kubernetes Service and the related cleanup. In contrast, Heroku Review Apps handles this all for you. Review Apps is really an awesome feature which allows for dev teams to easily get feedback from users and testers before merging into master, and I highly recommend it.

Review and Conclusion

Overall, Heroku Flow has impressed me with the feature set, intuitive integration with GitHub, and the ease of setup. I’m definitely going to be looking into this more both for myself and for my clients, as for smaller dev teams the ease of setup is invaluable, and even for larger teams, any decrease in overhead means more time to focus on the actual development task.

Topics:
ci/cd, ci/cd pipeline, continuous deployment, devops, heroku, web programming

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}