Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Dockerization instructions to README. #19

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>${application.home:-.}/logs/application.log</file>
<encoder>
<pattern>%date [%level] from %logger in %thread - %message%n%xException</pattern>
</encoder>
</appender>
...
<appender name="ASYNCFILE" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="FILE" />
</appender>
```

### 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 <project-name>:<project-version>
```

## Looking for some other frontend framework or language choice

* [Java Play React Seed](https://github.com/yohangz/java-play-react-seed)
Expand Down