Guide to Upgrading To The Latest Heroku Stack
Heroku’s cloud platform has helped deploy over 5 million web and mobile applications. Its ease of use has made it one of the most favored ways to launch customer-facing applications. Heroku provides the necessary infrastructure that businesses need to run applications so developers can focus on building your customer facing applications. An added advantage is that it accommodates most deployment languages including Java, Node.js, Scala, Clojure, Python, PHP, and Go.
Heroku stacks
Heroku has a list of stacks that applications can run on that are curated and maintained by Heroku. Every stack on Heroku supports different operating system packages and language runtime versions.
Every once in a while, like any other software, specific stacks do get deprecated and newer versions with better security and bug fixes are released.If your application is running on an older stack you need to migrate to the latest stack available. An older stack can compromise the performance of your app and prevent you from making changes on your application.
Step by step of upgrading your stack
Upgrading your stack is a straightforward process and these steps will guide you on what you need to do from checking your stack version to setting and deploying your app with the upgraded stack.
Check your stack version
To check your current heroku stack, you can use the console to run heroku stack or just login to your heroku and view app information for a particular application. Also, Heroku will show you if there's a new version of the stack..
Heroku currently supports 2 stacks Heroku-18 and Heroku-20. Heroku-20 is based on Ubuntu 20.04, and is now the default stack when creating new applications.
Depending on what application framework your app is using, Heroku does provide a list of compatible versions for each of its stacks. For Example, a ruby on rails app running on heroku stack 20 should have at least a ruby version of 2.x.x and rails 5.x.x. After determining what stack your application is currently using, you must decide which stack to migrate to. In general, you should always move to the very latest available stack,
To view a list of current Heroku stacks, check here
Create a test app
You might need to make code changes when you move an app to a different stack. Before upgrading it is best to run the new stack on a test app. A review app as previously mentioned is a great way to see if there are factors in the production environment that will make the new stack incompatible before you make changes to your app.
For example, on ruby on rails, this will involve deploying a branch with a new Ruby version to a Preview app on a newer Heroku stack.
Additionally, in order to determine if your app is fully functional while operating on the new stack, you must also mirror any add-ons that have been used in your application in the test app you create.
Setting your new stack
Once you have confirmed that the ruby and rails versions meet the requirements for a particular stack upgrade, run this command to set your heroku stack to the needed version.
In the command below, we are setting heroku-20 as the stack.
heroku stack:set heroku-20 -a appname
That will output:
stack set, next release on app name will use heroku-20
Run `git push Heroku master` to create a new release on heroku-20
The above command should be run locally within your application directory. When successfully run, the next heroku push or deployment should be fully set to the required stack.
Deploying the stack upgrade onto production
Heroku does not deploy the stack changes to the current app for an already existing app. For apps that have previously been built the upgrade will take effect on the next deployment. For apps where code has never been deployed, the stack change will take immediate effect and so for them a new deployment is not required.
Leveraging the Container Stack
In some cases, your app may be running on a very old framework or language version and it might be easier to to rather use the Heroku container stack. This allows you to containerize the app and then deploy it to heroku on the container stack. For example an app running on ruby 1.x.x and rails 2.x.x,
For details on how to deploy on heroku container stack, read here
If you or anyone you know has an app running on Heroku that needs infrastructure maintenance including upgrades, bug fixes and feature improvements, feel free to contact us here.