Skip to content

Commit

Permalink
Dockerised server support.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariano Gappa committed Feb 24, 2016
1 parent 4ae98a8 commit 7573087
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 4 deletions.
13 changes: 13 additions & 0 deletions Dockerfile
@@ -0,0 +1,13 @@
FROM jeanblanchard/java:8

RUN mkdir -p /lib

WORKDIR /

ADD /target/pack/lib /lib
ADD /target/pack/ostinato.jar /lib/
ADD /target/pack/bin/main /ostinato

EXPOSE 51234

ENTRYPOINT ["/ostinato"]
7 changes: 7 additions & 0 deletions build.sbt
@@ -1,5 +1,9 @@
import sbt.Keys._

name := "ostinato"

version := "0.1-SNAPSHOT"

enablePlugins(ScalaJSPlugin)

scalaJSUseRhino in Global := false
Expand Down Expand Up @@ -38,3 +42,6 @@ lazy val ostinato = crossProject.in(file(".")).
lazy val js = ostinato.js

lazy val jvm = ostinato.jvm

// https://github.com/xerial/sbt-pack
packAutoSettings
46 changes: 46 additions & 0 deletions docker-build.sh
@@ -0,0 +1,46 @@
#!/usr/bin/env bash

set -e

PROJECT_VERSION=$(./version.sh)
PROJECT_SCALA_VERSION=$(./scalaMajorVersion.sh)

NAME="ostinato"
ZIP_NAME="${NAME}-${PROJECT_VERSION}"
ZIP_PATH="target/${ZIP_NAME}"

# Docker image name and tag
IMAGE_NAME=$1
TAG=$2

SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
cd $SCRIPT_DIR

if [ -z "$IMAGE_NAME" ] ; then
cat << 'EOF'
Usage: ./docker-build.sh <image-name> <tag>
e.g.: ./docker-build.sh ostinato-server test
EOF
exit 1
fi

if [[ ! -f "${ZIP_PATH}.zip" ]]; then
echo >&2 "Please run 'sbt packArchiveZip' first."
exit 1
fi

find $SCRIPT_DIR -name "${ZIP_NAME}.zip" -exec unzip -o {} -d target/ \;
mkdir -p target/pack/lib
mv -f -v target/${ZIP_NAME}/lib/* "target/pack/lib"

#TODO remove sjs files
rm target/pack/lib/*_sjs*.jar

echo "Moving $IMAGE_NAME jar out of lib folder so that there are less changes to be added to the docker image"
mv target/pack/lib/$NAME*.jar target/pack/$NAME.jar


echo "Creating the docker image ${IMAGE_NAME}:${TAG}"
docker build --quiet=false -t $IMAGE_NAME:$TAG .
5 changes: 2 additions & 3 deletions jvm/src/main/scala/ostinato/chess/server/Main.scala
@@ -1,7 +1,7 @@
package ostinato.chess.server

import akka.actor.ActorSystem
import akka.event.{LoggingAdapter, Logging}
import akka.event.{ LoggingAdapter, Logging }
import akka.http.scaladsl.Http
import akka.http.scaladsl.server.Directives._
import akka.stream.ActorMaterializer
Expand All @@ -15,8 +15,7 @@ object Main extends App with OstinatoServerRoute {
val config = ConfigFactory.load()
val logger = Logging(system, getClass)


val bindingFuture = Http().bindAndHandle(route, "localhost", 51234)
val bindingFuture = Http().bindAndHandle(route, "127.0.0.1", 51234)
}

trait OstinatoServerRoute {
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Expand Up @@ -2,4 +2,4 @@ logLevel := Level.Warn

addSbtPlugin("org.scala-js" %% "sbt-scalajs" % "0.6.7")

addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.1.0")
addSbtPlugin("org.xerial.sbt" % "sbt-pack" % "0.7.9")
26 changes: 26 additions & 0 deletions scalaMajorVersion.sh
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

# Echoes the build.sbt project scala major version to STDOUT.
# e.g. Major version of 2.11.7 is 2.11
#
# NOTES:
# - place this script on the root of your project
# - this script should then find a build.sbt inside your project
# - this script assumes your project version setting is a literal e.g.: `version := "0.1-SNAPSHOT"`

# Exit on unset variables or if any of the following commands returns non-zero
set -eu

# cd to path of current script
# (based on http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in)
SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
cd $SCRIPT_DIR

# Find the first build.sbt in the path tree of this script,
# find the version line and extract the content within double quotes
find '.' -name "build.sbt" |
head -n1 |
xargs grep '[ \t]*scalaVersion :=' |
head -n1 |
sed 's/.*"\(.*\)".*/\1/' |
sed 's/^\([0-9]*\.[0-9]*\)\.[0-9]*$/\1/'
26 changes: 26 additions & 0 deletions version.sh
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

# Echoes the build.sbt project version to STDOUT.
#
# NOTES:
# - place this script on the root of your project
# - this script should then find a build.sbt inside your project
# - this script assumes your project version setting is a literal e.g.: `version := "0.1-SNAPSHOT"`

# Exit on unset variables or if any of the following commands returns non-zero
set -eu

# cd to path of current script
# (based on http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in)
SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
cd $SCRIPT_DIR

# Find the first build.sbt in the path tree of this script,
# find the version line and extract the content within double quotes
find '.' -name "build.sbt" |
head -n1 |
xargs grep '[ \t]*version :=' |
head -n1 |
sed 's/.*"\(.*\)".*/\1/'

# check for updates to this script at https://gist.github.com/MarianoGappa/265876f9e69505b4635e

0 comments on commit 7573087

Please sign in to comment.