Skip to content

Instantly share code, notes, and snippets.

@alterationx10
Last active November 7, 2016 03:46
Show Gist options
  • Save alterationx10/2128b0305b74b84335bf9b9e1a7b425a to your computer and use it in GitHub Desktop.
Save alterationx10/2128b0305b74b84335bf9b9e1a7b425a to your computer and use it in GitHub Desktop.
Start getting your Play Framework app to work with convox
name := """play_app"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.11.7"
libraryDependencies ++= Seq(
cache,
ws,
)
// Docker / Convox stuff
import com.typesafe.sbt.packager.docker._
// Pass the option to enable HTTPS
javaOptions in Universal ++= Seq(
"-Dhttps.port=9443"
)
// convox will want the staging directory to be the name of the app for things like
// convox deploy
// default is stagingDirectory := (target in Docker).value / "stage"
// (./target/docker/stage)
// so we will update this accordingly, since our app likely won't be named "stage".
val convoxAppName = "convox-app-name"
stagingDirectory in Docker := (target in Docker).value / convoxAppName
// Copy our convox files to the target stage directory.
// The default WORKDIR is /opt/docker, but we want these in the root with the Dockerfile,
// so we put them back two levels ../../
mappings in Universal += file("convox/docker-compose.yml") -> "../../docker-compose.yml"
mappings in Universal += file("convox/.dockerignore") -> "../../.dockerignore"
mappings in Universal += file("convox/.env") -> "../../.env"
// No need for a 700+MB Java image when we can have one < 110MB
dockerBaseImage := "openjdk:8-jre-alpine"
// The generated start file uses bash, so we install it on the alpine-based image
// Add it immediately after the "FROM" that goes in the Dockerfile
dockerCommands := dockerCommands.value.flatMap{
case cmd@Cmd("FROM",_) => List(cmd, Cmd("RUN", "apk update && apk add bash"))
case other => List(other)
}
// For convox, our docker-compose.yml file will run our app, so strip ENTRYPOINT from
// being put into the Dockerfile.
dockerCommands := dockerCommands.value.filterNot {
case ExecCmd("ENTRYPOINT", _) => true
case cmd => false
}
// Open the ports!
dockerExposedPorts := Seq(9000, 9443)
// Now you can:
// activator docker:stage (or sbt docker:stage)
// cd target/docker/stage
// and start using the convox tool from there!
version: '2'
services:
web:
build: .
command: bin/play_app
lables:
- convox.port.443.protocol=https
ports:
- 80:9000
- 443:9443
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment