Heroku is a PaaS(Platform as a Service) for running web apps that makes it as simple as a git push to deploy. They offer a free tier that is great for demos or quick testing environments and services such as redis, postgres, and many others.
There are a few minor changes from the default heroku gradle build pack to get your Grails 4 app run.
heroku will run the task
stage to get your app ready. You could add a gradle task named
stage or change the default task by running:
$ heroku config:set GRADLE_TASK="assemble"
Procfile is used to tell
heroku how to start your app, in this case, we need to pass the dynamically assigned port to our app, along with heroku's JAVA_OPTS. Lastly, tell it where gradle put our war/jar.
web: java -Dserver.port=$PORT $JAVA_OPTS -jar build/libs/*.war
If you'd like to run on OpenJDK 11 - create a
system.properties file with the following:
And thats it. Push to Heroku and your app will build and deploy in about a minute.
$ git push heroku master Enumerating objects: 3, done. Counting objects: 100% (3/3), done. Delta compression using up to 8 threads Compressing objects: 100% (2/2), done. Writing objects: 100% (2/2), 227 bytes | 227.00 KiB/s, done. Total 2 (delta 1), reused 0 (delta 0) remote: Compressing source files... done. remote: Building source: remote: remote: -----> Gradle app detected remote: -----> Installing JDK 11... done remote: -----> Building Gradle app... remote: -----> executing ./gradlew assemble remote: > Task :compileJava NO-SOURCE remote: > Task :compileGroovy remote: > Task :buildProperties remote: > Task :processResources remote: > Task :classes remote: > Task :compileGsonViews remote: > Task :findMainClass remote: > Task :bootWar remote: > Task :war SKIPPED remote: > Task :assemble remote: remote: BUILD SUCCESSFUL in 25s remote: 6 actionable tasks: 6 executed remote: -----> Discovering process types remote: Procfile declares types -> (none) remote: remote: -----> Compressing... remote: Done: 117.2M remote: -----> Launching... remote: Released v21 remote: https://my-app.herokuapp.com/ deployed to Heroku remote: remote: Verifying deploy... done. To https://git.heroku.com/my-app.git 905744b..b239ff4 master -> master