In Play, you can use multiple config files (application.conf, prod.conf...). Usually you would have a default conf file, i.e. application.conf, and let the other files import it and overload specific values.
One case is for example when you have a production database and wand to overwrite access configuration values set by developers and use credentials only known to the production personnel.
Here is a manual on this topic that say that the wanted config is to be specified as a parameter when running the application
I am deploying my application onto Heroku, which takes care of running the application. The only peace missing here and I can't find is how to tell Heroku which config file to load?
I solved this by using a Procfile with the contents:
web: target/universal/stage/bin/my_app -Dhttp.port=$PORT -Dconfig.resource=my-special.conf
You can define environment variables for your Heroku app, e.g. using the heroku config CLI command:
heroku config:set PLAY_CONFIG_FILE=application.conf
See Heroku config vars.
Related
Here is a question about the Heroku CLI.
When I run this command inside my local folder for a given app already on the server:
heroku config
I get a list of my environment variables settings.
But if I run the same command from another folder with the same name it does not work anymore.
This shows that the name of the local folder is not enough for heroku config to know which app I am thinking about.
How does heroku config know which app to query on the server?
By default, Heroku infers the app from your Git remotes:
App commands are typically executed from within an app’s local git clone. The app name is automatically detected by scanning the git remotes for the current working copy, so you don’t have to specify which app to operate on explicitly.
You can also explicitly tell it what app to use:
If you have multiple heroku remotes or want to execute an app command outside of a local working copy, you can specify the remote name or an explicit app name as follows:
heroku apps:info --app example
heroku apps:info --remote production
Or via environment variable:
Alternatively, the app name can be specified by setting the HEROKU_APP environment variable.
Now I am trying to deploy PlayApplication, but unfortunately my deploy failed. And the error code is H10, so probably I assume the problem is setting files because my database setting must be true as I can connect database by using the created username, password and URL.
And in my understanding, Procfile just shows a command to be run toward dynos and in tutorials, in terms of Java the procfile is like this:
web: java -jar target/helloworld.jar
However, in my application, the Procfile is web: target/start -Dhttp.port=${PORT} ${JAVA_OPTS} -Dconfig.file=conf/application_prod.conf where conf/application_prod.conf is the path to the setting file. Is this Procfile right?
My play version is 2.2.1 and the official document says web: target/universal/stage/bin/retailos -Dhttp.port=${PORT} -DapplyEvolutions.default=true -Ddb.default.driver=org.postgresql.Driver -Ddb.default.url=${DATABASE_URL} is good and I can also use the option -Dconfig.file= and then you can indicate where the setting file is. This means web: target/universal/stage/bin/retailos -Dhttp.port=${PORT} -DapplyEvolutions.default=trueBut -Dconfig.file=conf/application_prod.conf. But it does not work well.
And there are many candidates about the right way being also indicted by How to create play heroku procfile?.
I am really confused. I already have written all DB settings into application_prod.conf, so I prefer to use -Dconfig.file=.
What is exactly the true one?
Thanks.
Using -Dconfig.file and similar is definitely a good idea, you do not need to set all config parameters in your Procfile.
The reason it doesn't work is probably because you're using a file path for your config file, which to my knowledge doesn't work when the application is deployed as a jar. Try this instead:
-Dconfig.resource=application_prod.conf
Our team is using foreman for development and .env files to preassign development ports to each piece of a service oriented application. It dramatically simplifies things for this file to just live with the repository as we are not doing any specific per-machine local configurations even though multiple docs seem to think this is a bad idea.
Does anybody know if Heroku will ignore these .env files automatically? What if they were added to .slugignore?
I setup a test app to try this out including a PORT=5005 in the .env file and then committing/deploying to Heroku. Heroku didn't seem to notice it was even there and no new config vars appeared when I checked heroku config.
You answered your own question, but just for confirmation: .env is entirely a Foreman construct, while Foreman and Heroku will make use of Procfile.
We actually wanted to be able to ensure consistent environments between local and Heroku deployments, so I wrote a python script to export .env up to Heroku.
In case others want to export .env to Heroku:
https://github.com/FinalsClub/karmaworld/blob/68f0f0340d7b6420e263cab648ff7de1ea851a0e/export_env_to_heroku.py
I have a Play! application which is on Heroku.
My config file is different between my local application and the same on Heroku. Especially for the URL of my MongoDB base.
On localhost my base address is 127.0.0.1 and on heroku it's on MongoHQ. So when I push my application to Heroku I modify my config file.
But some times, like this morning Heroku change the config file. I pushed my application correctly configured on Heroku this morning and everything worked until now.
When I watch the logs I see that Heroku changed my config and try to connect to my local MongoDB base.
Is someone knowing what ? I hope I'm clear :)
Thanks everybody !
If there are differences in your application in different environments (e.g. local vs production), you should be using assigning the values with environment variables. For Play apps, you can use environment variables in your application.conf file, like this:
`mongo.url=${MONGO_URL}`
Then, on Heroku you can set the environment variables with config vars, like this (note, this may already be assigned for you by the add-on provider):
$ heroku config:add MONGO_URL=...
Locally, you can use Foreman to run your application with the environment variables stored in an .env file in your project root.
My app is a Ruby rack app. When my Heroku app starts it breaks because
/app/config.ru:8:in `read': No such file or directory - config/database.yml (Errno::ENOENT)
Why does this happen? I understood Heroku is meant to create this file https://devcenter.heroku.com/articles/cedar-migration
The database credentials will still be configured automatically: at slug compile time, a config/database.yml that parses the DATABASE_URL from the environment will be written into the app.
Frustratingly the doc at https://devcenter.heroku.com/articles/ruby doesn't explain about database.yml
Ok, the first thing - heroku does not use database.yml file. By default rails app loading it from config/ directory automatically. And it's no need to load it manually in config.ru. If you want to use in heroku PosgreSQL - just add add-on. Heroku wil do all other things to link your app and db. If you want to use external MySQL server you should use Amazon RDS add-on
heroku addons:add amazon_rds url=mysql2://user:pass#dbhost/dbname
By this you can use any db. I use GoDaddy mysql bases through the Amazon RDS add-on.
Any way, the problem in your config.ru 8th line something like
read 'config/database.yml'
Delete it and look other ways that not conflicted with heroku
Good luck
It appears Heroku only creates its config/database.yml if you have a folder config under source control. Not explained in docs.