解析application.conf时播放无法读取Heroku config vars [英] Play can't read Heroku config vars when parsing application.conf

查看:93
本文介绍了解析application.conf时播放无法读取Heroku config vars的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在部署一个用Play写的应用程序框架1.2.3到heroku(雪松堆栈),我通过

  heroku配置设置一些环境变量:添加DB_NAME =FOO 

这些设置为OK(通过heroku配置--app appname查看)。通过手动调用System.getenv()和通过

  morphia.db.name = $ {DB_NAME} 

机制。这个策略在本地工作很好,但是在heroku上,环境变量看起来似乎没有被读取,并且push到heroku失败了,因为它不能替代变量。由play发出的警告是:

 警告:无法在配置中替换DB_NAME(morphia.db.name = $ {DB_NAME})

它因为无法连接到数据库而死亡,这是一个致命的错误。它也会在错误中报告尝试连接到$ {HOST}:$ {PORT},因此在此不进行替换。我在这里遗漏了一些东西,或者说这根本就不适用于Play!目前在heroku上的应用程序?应该如何做?

解决方案

推送到Heroku会启动您的Play应用程序的预编译,然后读取您的应用程序.conf文件。不幸的是,Heroku配置变量在构建时不可用,所以你会看到你提到的那些警告:

 警告:无法在配置中替换VALUE(key = $ {VALUE})

但是,这不应该导致推到失败。也不应该导致您的应用程序无法运行。在运行时,Play重新读取application.conf,并且配置变量将会出现,并且它们的值将被替换。



在这种情况下,很难说出什么问题。您可以尝试的一件事就是像Heroku一样运行Play命令,看看你收到的内容:

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

注意单独的预编译步骤和prod框架id是不同的,如果你只是在这里运行你的应用程序:

  $ play运行

您还可以使用Heroku登录机票,有人可以查看您的应用程序。 p>

至少我们需要摆脱这些警告信息,因为你不是第一个注意到这个的消息。


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.

这篇关于解析application.conf时播放无法读取Heroku config vars的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆