Heroku - SoftwareSandbox/Fiazard GitHub Wiki

Setting up the Fiazard app on Heroku

We basically followed this walkthrough. However, we had to deal with some differences between the walkthrough and our Fiazard app. These differences, and how we dealt with them, are explained here.

Gradle

The walkthrough is based on a maven project, while we have a gradle project. Out of the box, Heroku provides a buildpack for gradle. By default, the gradle buildpack looks for a "stage" task in your gradle file. In our first attempt, we provided a task that just depends on the build task, like so:

task stage { dependsOn build }

The problem was that the integration tests were failing. The MongoDBRule that we use in our tests, is hardcoded to use a local MongoDB. Heroku doesn't provide a Mongo service like out Travis CI does. So, we changed our stage task so that it only assembles the app, without testing it.

task stage { dependsOn assemble }

Procfile

At this point, when we push to Heroku, our app will get assembled. But you still have to tell Heroku what to do with the app. You do this by providing a Procfile, which looks like this for our Fiazard app:

web: java $JAVA_OPTS -Ddw.server.applicationConnectors[0].port=$PORT -jar build/libs/Fiazard-0.0.1-SNAPSHOT.jar server src/main/resources/heroku.yml

There is a lot going on in this single line:

  • It tells Heroku to start our assembled jar as a java process
  • We provide 2 command line arguments, just like we do when we start our app in Eclipse.
  • Notice that we created a dedicated heroku.yml file, where we can configure some heroku-specific settings.
  • We also override the port property in the yml file with the $port variable provided by Heroku.
  • We pass in $java_opts provided by Heroku

Foreman

You can run your app locally using a procfile, by running the Foreman tool, which is installed together with the Heroku toolbelt. However, some changes were needed to the default Procfile. Therefore, we created a file called "Procfile.local".

web: java -jar build/libs/Fiazard-0.0.1-SNAPSHOT.jar server src/main/resources/dev.yml

  • We don't want to override the port (default port for foreman is 5000, yuk!)
  • Foreman (on windows) doesn't know $JAVA_OPTS (it should work with %JAVA_OPTS% but we couldn't get it to work)

Assigning a Dyno

At this point, the deployment looked succesful, but when we browsed to the application, it seemed like nothing was deployed. We could not find any hints in the log files about something being wrong. It turned out we still had to assign a dyno on the resources page of our Heroku app. Click the edit button and move the slider from 0 to 1.

MongoLab

Heroku doesn't provide a Mongo service out of the box. There are addons available, but they are not free or require a credit card. We didn't use an addon but directly created a Mongolab account and set up a fiazard database. The connection url for this database is configured in the heroku.yml file.

Config vars

Somewhere along the run, I read that we had to provide the mongo uri as an Heroku config var. This can be a way to remove the mongo uri from the heroku.yml file, since the yml file is public source code and the mongo uri contains the username and password. Config vars can be managed on the settings page.

Running application

The app runs as https://fiazard.herokuapp.com/. We added some toppings in the MongoLab DB. You can query them via http://fiazard.herokuapp.com/v1/toppings. For the moment, it has to be manually deployed. It would be nice if we could let travis deploy it on a green build... Also, for now, the app is located under the Heroku account of TimDM. We should get an Heroku account for Fiangulartje...

Sources