Play 2.0 Scala Heroku Instance Does Not See Every Variable in Procfile

I am using Play! 2.0 Scala Edition on Heroku. Heroku doesn't seem to see / use all of my configuration variables in Procfile.

For example, in my application.conf application, I have the following variables (among others):

mongodb.default.db = "nyancat" mongodb.default.host = "localhost" mongodb.default.port = 27017 

These should be the default values ​​for local development. However, I want the Heroku instance to use the MongoLabs instance. (Unfortunately, Salat is not configured with a URI, so I had to split it into a host, port, yada yada, i.e. MONGOLAB_URI is not used)

My Procfile now looks like this:

 β˜† cat Procfile web: target/start -Dsecurehostname="https://example.org" \ -Dhostname="http://example.org" -Dhttp.port=$PORT \ -DapplyEvolutions.default=true -Ddb.default.driver=org.postgresql.Driver \ -Ddb.default.url=$DATABASE_URL -Dredis=$REDISTOGO_URL \ -Dmailgun.apikey=$MAILGUN_API_KEY -Dmongodb.default.db="heroku_appXXXXXXX" \ -Dmongodb.default.host="dsXXXXXX.mongolab.com" -Dmongodb.default.port=XXXXX \ -Dmongodb.default.user="heroku_appXXXXXXX" \ -Dmongodb.default.password="foobared_not" 

I click and restart, but the remote MongoDB connection still says that it connects to localhost: 27017

Redis and everything else works fine and dandy.

The remote log shows this at startup, and it obviously does not contain all the parameters in my Procfile:

 2012-05-20T19:35:18+00:00 heroku[web.1]: Starting process with command \ `target/start -Dhostname="https://example.org" -Dhttp.port=XXXXX \ -DapplyEvolutions.default=true -Ddb.default.driver=org.postgresql.Driver \ -Ddb.default.url=<HIDDEN> -Dredis=<HIDDEN> -Dmailgun.apikey=<HIDDEN>` 

those. no mongo.* anywhere in the magazines.

Please let me know if I am missing something, thanks guys.


UPDATE

I tried emulating Heroku locally using the sbt stage and running the application using foreman start . I set the environment variables that Heroku will install and run them as follows:

 app git:(master) β˜† DATABASE_URL="jdbc:h2:mem:mydatabase;MODE=PostgreSQL" \ REDISTOGO_URL="redis://ignored: foobared@localhost :6379/" \ foreman start 20:20:27 web.1 | started with pid 43382 20:20:27 web.1 | Play server process ID is 43382 20:20:29 web.1 | [info] play - database [default] connected at jdbc:h2:mem:mydatabase 20:20:29 web.1 | [info] play - mongodb [default] connected at "heroku_appXXXXXXX"@"dsXXXXXX.mongolab.com":XXXXX/"heroku_appXXXXXXX" 20:20:30 web.1 | [info] play - Application started (Prod) 20:20:30 web.1 | [info] play - Listening for HTTP on port 5000... 

the foreman picks my values ​​MongoDB PRODUCTION, as in Procfile, which confirms my argument that Heroku may be using the old version of my Procfile for some unknown reason.

In my Heroku instance, Procfile definitely does not have the immutable flag set:

 ~ $ lsattr Procfile ------------------- Procfile 

UPDATE 2

I am using the MongoDB Salat plugin for Play Framework 2 (Scala only) .

Here is the template I selected:

Each click succeeded before I started implementing MongoDB support.

Then I turned on the Salat plugin , signed up for the MongoLabs account, and started to have fun. The plugin above does not support com.mongb.MongoURI and due to the way it analyzes the configuration, it will explode if you give it -Dmongodb.uri . It expects a key space, such as "default".

Which brings us back to the mongodb.default.* Switches that I used above.

Now my development cycle is as follows:

 push, fail push (without changes), success, but seemingly with old Procfile <make change> push, fail push (without changes), success, but seemingly with old Procfile <make change> push, fail push (without changes), success, but seemingly with old Procfile ... 

And most annoyingly, the failed push just logs this:

 Heroku push rejected due to an unrecognized error. 

... and the output of heroku logs -t shows this only:

 2012-05-22T07:23:59+00:00 heroku[slugc]: Slug compilation failed: unrecognized error 

It works locally, BTW.

I brought all this up, so Heroku maintains attention, as it may be that they swallow the errors thrown by Configafe Config , when it can just make things clearer from the start.

I also asked them not to let this second press succeed, but then use the old Procfile. Very misleading.

Needless to say, I now also support MongoURI support for the Salat plugin.


UPDATE 3

I implemented support for mongodb.default.uri on Play! The Salat plugin (and deployed it with lib /), but Heroku still throws an error whenever I click on something like mongo in my Procfile.

I asked Heroku to support the same question, and maybe someone here can answer: does Heroku make variables that you can use in Procfile?

0
source share
4 answers

Please note that the Procfile launch command can be a maximum of 255 characters . I expect all your mongodb configurations to be above this.

I suggest you refer to an alternative configuration file. for your variable environment variable dependent configurations For example:

 web: target/start -Dhttp.port=$PORT -Ddb.default.url=$DATABASE_URL \ -Dredis=$REDISTOGO_URL -Dmailgun.apikey=$MAILGUN_API_KEY \ -Dconfig.resource=heroku-prod.conf 

And in conf / heroku-prod.conf:

 include "application.conf" securehostname="https://example.org" hostname="http://example.org" applyEvolutions.default=true db.default.driver=org.postgresql.Driver mongodb.default.db="heroku_appXXXXXXX" mongodb.default.host="dsXXXXXX.mongolab.com" mongodb.default.port=XXXXX \ mongodb.default.user="heroku_appXXXXXXX" mongodb.default.password="foobared_not" 
+4
source

Maybe some variables are included by plugins? I did not test the api hero, but this may be the key.

The second point is how you accessed these variables, I believe that the type configuration system does not drop command line parameters.

Last point according to https://github.com/playframework/Play20/blob/master/framework/src/play/src/main/scala/play/api/Configuration.scala you can add application.conf to the root of the path to classes, it will be used in production mode instead of explicitly extracting it from conf /.

My 2c

0
source

You can also try to do your configuration as follows in application.conf ....

I'm not sure if this hero is in production mode or something else, but I noticed something strange with regard to environment variables set also with the "heroku" configuration.

In application.conf if using notation

 google.client=$(GOOGCLIENTID) 

everything works fine on the local workstation. I can check with the 'heroku config' that the variable is set, but it does not explicitly apply to the configuration when working on heroku.

However, this notation works fine:

 google.client=$(?GOOGCLIENTID) 

Hope this helps.

0
source

Are there any funny characters in $ MAILGUN_API_KEY? Try moving -Dmailgun.apikey = $ MAILGUN_API_KEY to the end ...

0
source

Source: https://habr.com/ru/post/1432510/


All Articles