diff --git a/Vagrantfile b/Vagrantfile index b47fde806..749494ef7 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -3,7 +3,7 @@ BOX_NAME = ENV["BOX_NAME"] || "trusty" BOX_URI = ENV["BOX_URI"] || "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box" -BOX_MEMORY = ENV["BOX_MEMORY"] || "512" +BOX_MEMORY = ENV["BOX_MEMORY"] || "1024" DOKKU_DOMAIN = ENV["DOKKU_DOMAIN"] || "dokku.me" DOKKU_IP = ENV["DOKKU_IP"] || "10.0.0.2" PREBUILT_STACK_URL = File.exist?("#{File.dirname(__FILE__)}/stack.tgz") ? 'file:///root/dokku/stack.tgz' : nil diff --git a/tests.mk b/tests.mk index 3c9b965b5..f7befd8bf 100644 --- a/tests.mk +++ b/tests.mk @@ -93,6 +93,10 @@ deploy-test-python-flask: @echo deploying python-flask app... cd tests && ./test_deploy ./apps/python-flask dokku.me +deploy-test-scala: + @echo deploying scala app... + cd tests && ./test_deploy ./apps/scala dokku.me + deploy-test-static: @echo deploying static app... cd tests && ./test_deploy ./apps/static dokku.me @@ -111,6 +115,7 @@ deploy-tests: @$(QUIET) $(MAKE) deploy-test-nodejs-express @$(QUIET) $(MAKE) deploy-test-php @$(QUIET) $(MAKE) deploy-test-python-flask + @$(QUIET) $(MAKE) deploy-test-scala @$(QUIET) $(MAKE) deploy-test-static test: setup-deploy-tests lint unit-tests deploy-tests diff --git a/tests/apps/scala/LICENSE b/tests/apps/scala/LICENSE new file mode 100644 index 000000000..72f2a4f99 --- /dev/null +++ b/tests/apps/scala/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2014 Joe Kutner + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/tests/apps/scala/Procfile b/tests/apps/scala/Procfile new file mode 100644 index 000000000..df7893e56 --- /dev/null +++ b/tests/apps/scala/Procfile @@ -0,0 +1 @@ +web: target/universal/stage/bin/scala-getting-started diff --git a/tests/apps/scala/README.md b/tests/apps/scala/README.md new file mode 100644 index 000000000..67d57f50b --- /dev/null +++ b/tests/apps/scala/README.md @@ -0,0 +1,33 @@ +# scala-getting-started + +A barebones Scala app, which can easily be deployed to Heroku. + +This application support the [Getting Started with Scala on Heroku](https://devcenter.heroku.com/articles/getting-started-with-scala) article - check it out. + +## Running Locally + +Make sure you have Scala and sbt installed. Also, install the [Heroku Toolbelt](https://toolbelt.heroku.com/). + +```sh +$ git clone https://github.com/heroku/scala-getting-started.git +$ cd scala-getting-started +$ sbt compile stage +$ foreman start web +``` + +Your app should now be running on [localhost:5000](http://localhost:5000/). + +## Deploying to Heroku + +```sh +$ heroku create +$ git push heroku master +$ heroku open +``` + +## Documentation + +For more information about using Scala on Heroku, see these Dev Center articles: + +- [Scala on Heroku](https://devcenter.heroku.com/categories/scala) + diff --git a/tests/apps/scala/build.sbt b/tests/apps/scala/build.sbt new file mode 100644 index 000000000..9b21b75f6 --- /dev/null +++ b/tests/apps/scala/build.sbt @@ -0,0 +1,14 @@ +import NativePackagerKeys._ + +packageArchetype.java_application + +name := """scala-getting-started""" + +version := "1.0" + +scalaVersion := "2.10.4" + +libraryDependencies ++= Seq( + "com.twitter" % "finagle-http_2.10" % "6.18.0", + "postgresql" % "postgresql" % "9.0-801.jdbc4" +) diff --git a/tests/apps/scala/check_deploy b/tests/apps/scala/check_deploy new file mode 100755 index 000000000..982d596fc --- /dev/null +++ b/tests/apps/scala/check_deploy @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +set -e; output="$(curl -s -S $1)"; echo $output; test "$output" == "Hello from Scala!" diff --git a/tests/apps/scala/project/build.properties b/tests/apps/scala/project/build.properties new file mode 100644 index 000000000..ed23aa291 --- /dev/null +++ b/tests/apps/scala/project/build.properties @@ -0,0 +1,4 @@ +#Activator-generated Properties +#Wed Aug 13 09:36:12 CDT 2014 +template.uuid=a855816c-0367-44ba-9adb-6a903f6ad599 +sbt.version=0.13.5 diff --git a/tests/apps/scala/project/plugins.sbt b/tests/apps/scala/project/plugins.sbt new file mode 100644 index 000000000..8f0a78407 --- /dev/null +++ b/tests/apps/scala/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "0.7.4") diff --git a/tests/apps/scala/src/main/scala/com/example/Server.scala b/tests/apps/scala/src/main/scala/com/example/Server.scala new file mode 100644 index 000000000..b11a41e64 --- /dev/null +++ b/tests/apps/scala/src/main/scala/com/example/Server.scala @@ -0,0 +1,65 @@ +package com.example + +import com.twitter.finagle.{Http, Service} +import com.twitter.util.{Await, Future} +import com.twitter.finagle.http.Response +import java.net.InetSocketAddress +import org.jboss.netty.handler.codec.http._ +import util.Properties +import java.net.URI +import java.sql.Connection +import java.sql.DriverManager + +object Server { + def main(args: Array[String]) { + val port = Properties.envOrElse("PORT", "8080").toInt + println("Starting on port: "+port) + + val server = Http.serve(":" + port, new Hello) + Await.ready(server) + } +} + +class Hello extends Service[HttpRequest, HttpResponse] { + def apply(request: HttpRequest): Future[HttpResponse] = { + if (request.getUri.endsWith("/db")) { + showDatabase(request); + } else { + showHome(request); + } + } + + def showHome(request: HttpRequest): Future[HttpResponse] = { + val response = Response() + response.setStatusCode(200) + response.setContentString("Hello from Scala!") + Future(response) + } + + def showDatabase(request: HttpRequest): Future[HttpResponse] = { + val connection = getConnection + val stmt = connection.createStatement + stmt.executeUpdate("CREATE TABLE IF NOT EXISTS ticks (tick timestamp)") + stmt.executeUpdate("INSERT INTO ticks VALUES (now())") + + val rs = stmt.executeQuery("SELECT tick FROM ticks") + + var out = "" + while (rs.next) { + out += "Read from DB: " + rs.getTimestamp("tick") + "\n" + } + + val response = Response() + response.setStatusCode(200) + response.setContentString(out) + Future(response) + } + + def getConnection(): Connection = { + val dbUri = new URI(System.getenv("DATABASE_URL")) + val username = dbUri.getUserInfo.split(":")(0) + val password = dbUri.getUserInfo.split(":")(1) + val dbUrl = "jdbc:postgresql://" + dbUri.getHost + dbUri.getPath + DriverManager.getConnection(dbUrl, username, password) + } +} diff --git a/tests/apps/scala/system.properties b/tests/apps/scala/system.properties new file mode 100644 index 000000000..97270b43f --- /dev/null +++ b/tests/apps/scala/system.properties @@ -0,0 +1 @@ +java.runtime.version=1.7