Do you want to deploy your applications instantly to a cloud environment? Heroku offers a free account to get you started right away! In this post we set up our Heroku playground and deploy an app.

You can read more on all other possibilities of Heroku at the Heroku Dev Center ducumentation here.

We will take the Kotlin application from a previous post on Micronaut and deploy it too Heroku. The complete code can be found on github here.

Heroku cli

To communicate with Heroku from your command line you have to install the Heroku cli. The installation guide for the Heroku cli here told me to do the following.

brew tap heroku/brew && brew install heroku

With the Heroku cli you can login to Heroku with the following command.

heroku login

If you don’t have a Heroku account yet you can create your free account by going to the Heroku signup page here. Inside your account we create a new app by clicking on New and providing a name (gardenplanner-api) and a region (europe).

Screenshot 2019 10 27 at 15.04.00 - HEROKU PLAYGROUND

Procfile

The Procfile is the instructions for Heroku to run your app. Our app is very simple and the Procfile reflects this. The web just specifies our app and then the normal jar command to run the app.

web: java -jar webapp/build/libs/webapp-0.1-all.jar

Next we do a series of command to deploy our app. We can collect them in a file deploy.sh that can be ran to trigger a deploy. We login, build our app, push the Docker image to the Heroku registry and release our app on Heroku.

heroku container:login
./gradlew stage
heroku container:push web --app gardenplanner-api
heroku container:release web --app gardenplanner-api

Note that we defined the gradle stage command ourselves.

task stage(dependsOn: ['build', 'clean'])
build.mustRunAfter clean

In the top right of the Heroku dashboard of our gardenplanner-api app we now see Open app. This displays the web address our app is publish on. Go to our endpoint and see that it works.

Screenshot 2019 10 27 at 15.16.00 - HEROKU PLAYGROUND

Hopefully you are now able to deploy your own apps to a Heroku playground. Happy herokuing!