diff --git a/README.md b/README.md index 4275b16..2f71f5d 100644 --- a/README.md +++ b/README.md @@ -160,6 +160,61 @@ GET /*file controllers.FrontendController.assetOrDefault(file) * Make output directory ROOT/public/ * Implement a proxy to localhost:9000 +## Dockerizing your application. + +Play's plugin already includes the [SBT Native Packager](https://www.scala-sbt.org/sbt-native-packager/) in your project, so containerizing your application is pretty straightforward. + +### ui-build.sbt + +`ui-build.sbt` needs to be told that we want to build our production code when we publish a docker container. Add the following line to `ui-build.sbt`. +```sbt +publishLocal in Docker := ((publishLocal in Docker) dependsOn `ui-prod-build`).value +``` + +### Configuration + +In order to run a docker container, a few configuration changes need to be made. First, add +```conf +play.server.pidfile.path=/dev/null +``` +to your conf/application.conf file. Each docker container is a single process, so we don't need play to monitor a pidfile. +Next, because the docker container will be running a production version of the build, we need to tell it to get a valid application secret from the container's environment. + +`conf/application.conf` already has a `play.http.secret.key` entry. Add the following line _after_ the already-present line. +```conf +play.http.secret.key=${?APPLICATION_SECRET} +``` + +### Logging + +Logging in a docker container is generally done to STDOUT, and then fetched with the `docker logs` command. The default logging set up in this project is to include writing out to a file at /opt/docker/logs/application.log. + +To solve this, we'll get rid of the file appender in `conf/logback.xml`. Remove the following lines: + +```xml + + ${application.home:-.}/logs/application.log + + %date [%level] from %logger in %thread - %message%n%xException + + + ... + + + +``` + +### Creating and Running your container + +To build the new docker container, run: +``` +sbt docker:publishLocal +``` +And to run it, use: +``` +docker run -i -t -p 9000:9000 -e APPLICATION_SECRET=$MY_APP_SECRET : +``` + ## Looking for some other frontend framework or language choice * [Java Play React Seed](https://github.com/yohangz/java-play-react-seed)