Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify play mode (prod, dev) when starting a "dist" application

I'd like to know how to start a packaged play v2.3.7 application (created by the dist command) in Prod and Dev modes.

We create our distributable artifact using sbt dist, which produces a zip file according to these instructions. We copy the zip file to the machine it will run on, unpack it, and start it according to the instructions on that page. However, it always starts so that Play.isProd evaluates to true.

When developing our application, we can start it using activator start, which causes Play.isProd to return true , or activator run / activator test, which cause Play.isProd to return false.

We'd like to know if there is any way to start the packaged application and be able to control the state of Play.isProd, so that we can have a test instance running on our test server, and a prod instance on our prod server.

Our current workaround is to have a custom setting in application.conf and examine that using Play.current.configuration.getBoolean("play_mode").getOrElse(true). I feel we should be using the built-in functionality instead.

like image 488
OldManLink Avatar asked Nov 09 '22 12:11

OldManLink


1 Answers

Not sure if I fully understand your questions, but here goes.

My spontaneous recommendation would be to use environment variables, as this always decouples configuration from code, and binds specific configuration to machine/environment.

But to answer your question :)

It is possible to have an additional .conf files and set the one to be used on start/run:

activator start "-Dconfig.resource=dev.conf"

Alternative if this is for a temporarily fix you could override specific configuration keys directly from command line:

activator start "-Dapplication.some.conf=override -Ddb.default.password=some_pass"

// This might even work, not sure
activator start "-Dapplication.mode=DEV"

Read more:

https://www.playframework.com/documentation/2.3.x/ProductionConfiguration

like image 138
Mikael Hellman Avatar answered Nov 14 '22 23:11

Mikael Hellman