score:3

Accepted answer

the referenced article is part 2 of a series, where the address of the container is passed into the java program by a script. the script itself is referenced in part 1.

mappings in universal takes a sequence of (file, string) tuples. the file is copied to the path specified by the string in the resulting image.

in this case, if there is no file present at basedirectory.value / "docker" / "start", then nothing is available to copy, and the resulting is the behavior you describe.

you should create an appropriate start script, as discussed in part 1.

score:3

another option is to make use of the experimental support for docker in sbt-native-packager.

if you remove the docker-related lines from build.sbt, and add a maintainer setting, you can:

sbt docker:stage generate a dockerfile and context in target/docker/stage

sbt docker:publishlocal generate a local image

sbt docker:publish generate an image and push it remotely

if you want to modify the commands passed to the start script, you can make modifications like this:

bashscriptextradefines := seq(
  "cluster_ip=$(/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}')",
  "addresidual ${cluster_ip}"
)

addresidual is a function in the start script generated by sbt-native-packager, that adds an extra parameter to the command line arguments for the program.

addjava is a function that adds an extra parameter to the java binary that runs your program.


your build.sbt might look like this:

import com.typesafe.sbt.packager.keys._

organization  := "com.confabulous"

name          := "deva"

version       := "0.0.1"

scalaversion  := "2.10.3"

scalacoptions := seq("-unchecked", "-deprecation", "-encoding", "utf8", "-language:postfixops")

resolvers ++= seq(
  "sonatype releases"  at "https://oss.sonatype.org/content/repositories/releases/",
  "sonatype snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/",
  "typesafe repo"      at "http://repo.typesafe.com/typesafe/releases/"
)

librarydependencies ++= seq(
  "ch.qos.logback"      %   "logback-classic" % "1.0.9",
  "com.typesafe.akka"   %   "akka-slf4j_2.10" % "2.3.3",
  "com.typesafe.akka"   %%  "akka-actor"      % "2.3.3",
  "com.typesafe.akka"   %%  "akka-remote"     % "2.3.3",
  "com.typesafe.akka"   %%  "akka-agent"      % "2.3.3",
  "com.typesafe.slick"  %%  "slick"           % "2.0.1-rc1",
  "org.mozilla"         %   "rhino"           % "1.7r4",
  "org.postgresql"      %   "postgresql"      % "9.3-1101-jdbc3",
  "org.msgpack"         %%  "msgpack-scala"   % "0.6.8",
  "com.livestream"      %%  "scredis"         % "1.1.2",
  "com.confabulous"     %%  "messages"        % "0.0.1-snapshot",
  "com.confabulous"     %%  "db"              % "0.0.1-snapshot"
)

packagearchetype.java_server

maintainer := "dan ellis <dan@halftreelabs.com>"

more information should be available from the sbt-native-packager documentation. comments are also welcome.


Related Query

More Query from same tag