typesafehub / conductr-lib

Other
8 stars 13 forks source link

Play: Set default port and ip #102

Closed markusjura closed 8 years ago

markusjura commented 8 years ago

For a Play project it is currently necessary to overwrite the http.port and http.address envs with the startCommand option in the build.sbt of the user project.

Example

BundleKeys.startCommand ++= Seq(
  "-Dhttp.address=$WEB_BIND_IP",
  "-Dhttp.port=$WEB_BIND_PORT"
)

In conductr-bundle-lib the current approach to automate setting these envs is by adding configuration to the Play application loader: https://github.com/typesafehub/conductr-lib/blob/master/play25-conductr-bundle-lib/src/main/scala/com/typesafe/conductr/bundlelib/play/api/Env.scala#L19-L20

Unfortunately, this approach doesn't work. Reason is that these envs are not used by Play when the netty server gets started. So Play will start itself inside of ConductR still on 0.0.0.0:9000. Instead it is necessary to override play.server.http.port and play.server.http.address in the overrides-referece.conf.

To keep things simple we override the port and address with the default endpoints (formerly web) instead of using the project name as a key. Otherwise it would be hard to resolve the particular name of the project inside the configuration file.

This PR has been tested with reactive-maps and chirper. I could see that the ip and port of the netty server is allocated properly. However, some other things were still not working (yet) with sbt-conductr 2.0.0. This PR is therefore still on WIP because I am not sure yet if this PR introduced this issues.

huntc commented 8 years ago

Where do the "DEFAULT" envs get set? ConductR doesn't supply them...

markusjura commented 8 years ago

default is the default endpoint and therefore DEFAULT_BIND_IP and DEFAULT_BIND_PORT is available. If BundleKeys.endpoints gets overridden then the user need to add specify a override http.port and http.address as well, e.g. by using BundleKeys.startCommand.

Open for suggestions here, but I don't see any better solution after fighting with this for the past day.

The related change with the default endpoint is made here https://github.com/typesafehub/sbt-conductr/pull/150.

huntc commented 8 years ago

LGTM - just rename DEFAULT back to WEB.

markusjura commented 8 years ago

Changed it to WEB.