Scala on OpenShift

This post will describe how to build a simple Scala application on OpenShift using a DIY cartridge.

First, create a DIY cartridge:

rhc app create -a scale -t diy-0.1

Edit the pre_build action hook to download and install the Scala Simple-Build-Tool (SBT):

cd $OPENSHIFT_DATA_DIR
if [[ -d sbt ]]; then
  echo “SBT installed”
else
  curl -o sbt.tgz http://scalasbt.artifactoryonline.com/scalasbt/sbt-native-packages/org/scala-sbt/sbt/0.12.2/sbt.tgz
  tar zxvf sbt.tgz sbt
  rm sbt.tgz
fi

Edit the build action hook to create and build a sample HelloWorld project:

SBT_PATH=$OPENSHIFT_DATA_DIR/sbt
SBT_DIR=$OPENSHIFT_DATA_DIR/project
IVY_DIR=$OPENSHIFT_DATA_DIR/.ivy
cd $OPENSHIFT_DATA_DIR
echo ‘object Hi { def main(args: Array[String]) = println(“Hi!”) }’ > ${SBT_DIR}/hw.scala
$SBT_PATH/bin/sbt -sbt-dir $SBT_DIR -ivy $IVY_DIR -mem 256 compile

Commit and push the changes:

[root@ip-10-34-137-190 scala]# git push
Counting objects: 9, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 624 bytes, done.
Total 5 (delta 2), reused 0 (delta 0)
remote: restart_on_add=false
remote: Done
remote: restart_on_add=false
remote: Running .openshift/action_hooks/pre_build
remote:   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
remote:                                  Dload  Upload   Total   Spent    Left  Speed
remote: 100 1060k  100 1060k    0     0  6599k      0 –:–:– –:–:– –:–:– 7914k
remote: sbt/
remote: sbt/jansi-license.txt
remote: sbt/bin/
remote: sbt/bin/sbt.bat
remote: sbt/bin/sbt-launch.jar
remote: sbt/bin/sbt
remote: sbt/bin/win-sbt
remote: sbt/bin/sbt-launch-lib.bash
remote: sbt/bin/classes/
remote: sbt/bin/classes/SbtJansiLaunch.class
remote: sbt/bin/jansi.jar
remote: Running .openshift/action_hooks/build
remote: /var/lib/openshift/51424742371b593a740001d9/app-root/runtime/repo/.openshift/action_hooks/build: line 10: /var/lib/openshift/51424742371b593a740001d9/app-root/data//project/hw.scala: No such file or directory
remote: Getting net.java.dev.jna jna 3.2.3 …
remote: downloading http://repo1.maven.org/maven2/net/java/dev/jna/jna/3.2.3/jna-3.2.3.jar …
remote:     [SUCCESSFUL ] net.java.dev.jna#jna;3.2.3!jna.jar (406ms)
remote: :: retrieving :: org.scala-sbt#boot-jna
remote:     confs: [default]
remote:     1 artifacts copied, 0 already retrieved (838kB/107ms)
remote: Getting org.scala-sbt sbt 0.12.2 …
remote: downloading http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/sbt/0.12.2/jars/sbt.jar …
remote:     [SUCCESSFUL ] org.scala-sbt#sbt;0.12.2!sbt.jar (97ms)
remote: downloading http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/main/0.12.2/jars/main.jar …
remote:     [SUCCESSFUL ] org.scala-sbt#main;0.12.2!main.jar (301ms)
remote: downloading http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/compiler-interface/0.12.2/jars/compiler-interface-src.jar …
remote:     [SUCCESSFUL ] org.scala-sbt#compiler-interface;0.12.2!compiler-interface-src.jar (50ms)
remote: downloading http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/compiler-interface/0.12.2/jars/compiler-interface-bin.jar …
remote:     [SUCCESSFUL ] org.scala-sbt#compiler-interface;0.12.2!compiler-interface-bin.jar (50ms)
remote: downloading http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/precompiled-2_8_2/0.12.2/jars/compiler-interface-bin.jar …
remote:     [SUCCESSFUL ] org.scala-sbt#precompiled-2_8_2;0.12.2!compiler-interface-bin.jar (50ms)
remote: downloading http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/precompiled-2_10_0/0.12.2/jars/compiler-interface-bin.jar …
remote:     [SUCCESSFUL ] org.scala-sbt#precompiled-2_10_0;0.12.2!compiler-interface-bin.jar (143ms)
remote: downloading http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/actions/0.12.2/jars/actions.jar …
remote:     [SUCCESSFUL ] org.scala-sbt#actions;0.12.2!actions.jar (57ms)
remote: downloading http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/interface/0.12.2/jars/interface.jar …
remote:     [SUCCESSFUL ] org.scala-sbt#interface;0.12.2!interface.jar (60ms)
remote: downloading http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/io/0.12.2/jars/io.jar …
remote:     [SUCCESSFUL ] org.scala-sbt#io;0.12.2!io.jar (54ms)
remote: downloading http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/ivy/0.12.2/jars/ivy.jar …
remote:     [SUCCESSFUL ] org.scala-sbt#ivy;0.12.2!ivy.jar (78ms)
remote: downloading http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/launcher-interface/0.12.2/jars/launcher-interface.jar …
remote:     [SUCCESSFUL ] org.scala-sbt#launcher-interface;0.12.2!launcher-interface.jar (52ms)
remote: downloading http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/logging/0.12.2/jars/logging.jar …
remote:     [SUCCESSFUL ] org.scala-sbt#logging;0.12.2!logging.jar (52ms)
remote: downloading http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/process/0.12.2/jars/process.jar …
remote:     [SUCCESSFUL ] org.scala-sbt#process;0.12.2!process.jar (73ms)
remote: downloading http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/run/0.12.2/jars/run.jar …
remote:     [SUCCESSFUL ] org.scala-sbt#run;0.12.2!run.jar (66ms)
remote: downloading http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/command/0.12.2/jars/command.jar …
remote:     [SUCCESSFUL ] org.scala-sbt#command;0.12.2!command.jar (56ms)
remote: downloading http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/classpath/0.12.2/jars/classpath.jar …
remote:     [SUCCESSFUL ] org.scala-sbt#classpath;0.12.2!classpath.jar (57ms)
remote: downloading http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/completion/0.12.2/jars/completion.jar …
remote:     [SUCCESSFUL ] org.scala-sbt#completion;0.12.2!completion.jar (59ms)
remote: downloading http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/api/0.12.2/jars/api.jar …
remote:     [SUCCESSFUL ] org.scala-sbt#api;0.12.2!api.jar (59ms)
remote: downloading http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/compiler-integration/0.12.2/jars/compiler-integration.jar …
remote:     [SUCCESSFUL ] org.scala-sbt#compiler-integration;0.12.2!compiler-integration.jar (50ms)
remote: downloading http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/compiler-ivy-integration/0.12.2/jars/compiler-ivy-integration.jar …
remote:     [SUCCESSFUL ] org.scala-sbt#compiler-ivy-integration;0.12.2!compiler-ivy-integration.jar (50ms)
remote: downloading http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/task-system/0.12.2/jars/task-system.jar …
remote:     [SUCCESSFUL ] org.scala-sbt#task-system;0.12.2!task-system.jar (51ms)
remote: downloading http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/tasks/0.12.2/jars/tasks.jar …
remote:     [SUCCESSFUL ] org.scala-sbt#tasks;0.12.2!tasks.jar (59ms)
remote: downloading http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/tracking/0.12.2/jars/tracking.jar …
remote:     [SUCCESSFUL ] org.scala-sbt#tracking;0.12.2!tracking.jar (70ms)
remote: downloading http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/testing/0.12.2/jars/testing.jar …
remote:     [SUCCESSFUL ] org.scala-sbt#testing;0.12.2!testing.jar (52ms)
remote: downloading http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/control/0.12.2/jars/control.jar …
remote:     [SUCCESSFUL ] org.scala-sbt#control;0.12.2!control.jar (52ms)
remote: downloading http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/collections/0.12.2/jars/collections.jar …
remote:     [SUCCESSFUL ] org.scala-sbt#collections;0.12.2!collections.jar (67ms)
remote: downloading http://repo1.maven.org/maven2/jline/jline/1.0/jline-1.0.jar …
remote:     [SUCCESSFUL ] jline#jline;1.0!jline.jar (22ms)
remote: downloading http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/incremental-compiler/0.12.2/jars/incremental-compiler.jar …
remote:     [SUCCESSFUL ] org.scala-sbt#incremental-compiler;0.12.2!incremental-compiler.jar (65ms)
remote: downloading http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/compile/0.12.2/jars/compile.jar …
remote:     [SUCCESSFUL ] org.scala-sbt#compile;0.12.2!compile.jar (50ms)
remote: downloading http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/persist/0.12.2/jars/persist.jar …
remote:     [SUCCESSFUL ] org.scala-sbt#persist;0.12.2!persist.jar (70ms)
remote: downloading http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/classfile/0.12.2/jars/classfile.jar …
remote:     [SUCCESSFUL ] org.scala-sbt#classfile;0.12.2!classfile.jar (52ms)
remote: downloading http://repo1.maven.org/maven2/org/scala-tools/sbinary/sbinary_2.9.0/0.4.0/sbinary_2.9.0-0.4.0.jar …
remote:     [SUCCESSFUL ] org.scala-tools.sbinary#sbinary_2.9.0;0.4.0!sbinary_2.9.0.jar (226ms)
remote: downloading http://repo1.maven.org/maven2/org/apache/ivy/ivy/2.3.0-rc1/ivy-2.3.0-rc1.jar …
remote:     [SUCCESSFUL ] org.apache.ivy#ivy;2.3.0-rc1!ivy.jar (116ms)
remote: downloading http://repo1.maven.org/maven2/com/jcraft/jsch/0.1.46/jsch-0.1.46.jar …
remote:     [SUCCESSFUL ] com.jcraft#jsch;0.1.46!jsch.jar (37ms)
remote: downloading http://repo1.maven.org/maven2/commons-httpclient/commons-httpclient/3.1/commons-httpclient-3.1.jar …
remote:     [SUCCESSFUL ] commons-httpclient#commons-httpclient;3.1!commons-httpclient.jar (43ms)
remote: downloading http://repo1.maven.org/maven2/commons-logging/commons-logging/1.0.4/commons-logging-1.0.4.jar …
remote:     [SUCCESSFUL ] commons-logging#commons-logging;1.0.4!commons-logging.jar (21ms)
remote: downloading http://repo1.maven.org/maven2/commons-codec/commons-codec/1.2/commons-codec-1.2.jar …
remote:     [SUCCESSFUL ] commons-codec#commons-codec;1.2!commons-codec.jar (20ms)
remote: downloading http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/cache/0.12.2/jars/cache.jar …
remote:     [SUCCESSFUL ] org.scala-sbt#cache;0.12.2!cache.jar (58ms)
remote: downloading http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/test-agent/0.12.2/jars/test-agent.jar …
remote:     [SUCCESSFUL ] org.scala-sbt#test-agent;0.12.2!test-agent.jar (53ms)
remote: downloading http://repo1.maven.org/maven2/org/scala-tools/testing/test-interface/0.5/test-interface-0.5.jar …
remote:     [SUCCESSFUL ] org.scala-tools.testing#test-interface;0.5!test-interface.jar (19ms)
remote: :: retrieving :: org.scala-sbt#boot-app
remote:     confs: [default]
remote:     40 artifacts copied, 0 already retrieved (8381kB/176ms)
remote: Getting Scala 2.9.2 (for sbt)…
remote: downloading http://repo1.maven.org/maven2/org/scala-lang/scala-compiler/2.9.2/scala-compiler-2.9.2.jar …
remote:     [SUCCESSFUL ] org.scala-lang#scala-compiler;2.9.2!scala-compiler.jar (1808ms)
remote: downloading http://repo1.maven.org/maven2/org/scala-lang/scala-library/2.9.2/scala-library-2.9.2.jar …
remote:     [SUCCESSFUL ] org.scala-lang#scala-library;2.9.2!scala-library.jar (1086ms)
remote: downloading http://repo1.maven.org/maven2/org/scala-lang/jline/2.9.2/jline-2.9.2.jar …
remote:     [SUCCESSFUL ] org.scala-lang#jline;2.9.2!jline.jar (27ms)
remote: downloading http://repo1.maven.org/maven2/org/fusesource/jansi/jansi/1.4/jansi-1.4.jar …
remote:     [SUCCESSFUL ] org.fusesource.jansi#jansi;1.4!jansi.jar (18ms)
remote: :: retrieving :: org.scala-sbt#boot-scala
remote:     confs: [default]
remote:     4 artifacts copied, 0 already retrieved (20090kB/162ms)
remote: [info] Loading project definition from /var/lib/openshift/51424742371b593a740001d9/app-root/data/project
remote: [info] Updating {file:/var/lib/openshift/51424742371b593a740001d9/app-root/data/project/}default-19a144…
        [info] Resolving org.scala-sbt#precompiled-2_10_0;0.12.2 …
remote: [info] Done updating.
remote: [info] Set current project to default-e6de01 (in build file:/var/lib/openshift/51424742371b593a740001d9/app-root/data/)
remote: [info] Updating {file:/var/lib/openshift/51424742371b593a740001d9/app-root/data/}default-e6de01…
remote: [info] Resolving org.scala-lang#scala-library;2.9.2 …
remote: [info] Done updating.
remote: [success] Total time: 1 s, completed Mar 15, 2013 1:27:11 PM
remote: Running .openshift/action_hooks/deploy
remote: hot_deploy_added=false
remote: Done
remote: Running .openshift/action_hooks/post_deploy
To ssh://51424742371b593a740001d9@scala-bdecoste84e.dev.rhcloud.com/~/git/scala.git/
   527c554..8370f08  master -> master

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>