开发者

Play can't read Heroku config vars when parsing application.conf

开发者 https://www.devze.com 2023-04-07 12:44 出处:网络
I am deploying an app written with Play! Framework 1.2.3 to heroku (cedar stack) and I am setting some environment variables via

I am deploying an app written with Play! Framework 1.2.3 to heroku (cedar stack) and I am setting some environment variables via

heroku config:add DB_NAME="FOO"

These are set OK (seen via heroku config --app appname). These are read from the code both via manual calls to System.getenv() and substitutions done by play when reading application.conf via the

morphia.db.name=${DB_NAME}

mechanism. This tactic works well locally, but on heroku the environment variables are seemingly not read and the push to heroku fails since it can't substitute the variables. Warning emitted by play is:

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

And it开发者_运维百科 dies because it can't connect to the database, which is a fatal error. It also reports in the error as trying to connect to ${HOST}:${PORT}, so no substitution is performed here. Am I missing something here, or is this simply not working for Play! apps on heroku at present? How should this be done?


The push to Heroku initiates a precompile of your Play application which, in turn, reads your application.conf file. Unfortunately, the Heroku configuration variables aren't available at build time so you'll see those warnings that you mentioned:

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

However, this shouldn't cause the push to fail. Nor should it cause your app to fail to run. At runtime, Play re-reads application.conf and the configuration variables will be present and their values will get replaced.

It's hard to tell exactly what's wrong in this case. One thing you could try is running the Play commands just as Heroku does it and see what you get:

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

Note that the separate precompile step and the prod framework id are different then if you are just running your app locally like this:

$ play run

You can also log a ticket with Heroku and someone can take a look at your app.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消