Merge pull request #850 from progrium/mh-test-deploy-scala

test scala deployment
This commit is contained in:
Jose Diaz-Gonzalez
2014-12-24 14:23:28 -05:00
11 changed files with 148 additions and 1 deletions

2
Vagrantfile vendored
View File

@@ -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

View File

@@ -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

21
tests/apps/scala/LICENSE Normal file
View File

@@ -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.

View File

@@ -0,0 +1 @@
web: target/universal/stage/bin/scala-getting-started

View File

@@ -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)

View File

@@ -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"
)

2
tests/apps/scala/check_deploy Executable file
View File

@@ -0,0 +1,2 @@
#!/usr/bin/env bash
set -e; output="$(curl -s -S $1)"; echo $output; test "$output" == "Hello from Scala!"

View File

@@ -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

View File

@@ -0,0 +1 @@
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "0.7.4")

View File

@@ -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)
}
}

View File

@@ -0,0 +1 @@
java.runtime.version=1.7