Playback cannot read Heroku configuration files when parsing .conf application

I am using an application written in Play! Framework 1.2.3 for heroku (cedar stack) and I set some environment variables via

heroku config:add DB_NAME="FOO" 

They are configured in order (see heroku config --app appname application). They are read from the code using manual calls in System.getenv (), as well as from measurements taken during playback when reading application.conf using

 morphia.db.name=${DB_NAME} 

mechanism. This tactic works well locally, but the environment variables on the hero do not seem to be readable, and clicking on the hero fails because it cannot replace the variables. Warning generated by playback:

 WARNING: Cannot replace DB_NAME in configuration (morphia.db.name=${DB_NAME}) 

And he dies because he cannot connect to the database, which is a fatal error. It also reports an error as an attempt to connect to $ {HOST}: $ {PORT}, so replacement is not performed here. I missed something here, or it just doesn’t work for Play! apps on geroku now? How to do it?

+2
source share
1 answer

Clicking on Heroku initiates the precompilation of your Play application, which in turn reads your application.conf file. Unfortunately, Heroku configuration variables are not available at build time, so you will see these warnings that you mentioned:

 WARNING: Cannot replace VALUE in configuration (key=${VALUE}) 

However, this should not cause a failure. It should also not cause your application to not start. At run time, Play reads application.conf again and configuration variables will be present and their values ​​will be replaced.

It is hard to say exactly what is wrong in this case. One thing you can try is to run the Play commands just like Heroku does, and see what you get:

 $ play precompile $ play run --http.port=5000 --%prod -Dprecompiled=true 

Note that the separate pre-compilation step and the prod database identifier are different if you simply run the application locally as follows:

 $ play run 

You can also register a ticket with Heroku, and someone can take a look at your application.

At the very least, we need to get rid of these WARNING messages, because you are not the first to notice this.

+4
source

All Articles