使用Scalatra在Heroku上部署

时间:2016-05-24 23:43:38

标签: scala heroku scalatra scalatra-sbt

我正在尝试在heroku中部署我的Scalatra Web应用程序,但我遇到了一个问题。

我的应用程序在本地使用SBT并使用“heroku local web”。我正在使用heroku sbt插件。

当我使用“sbt stage deployHeroku”时,应用程序上传并正确启动,获取:

network.host: 0.0.0.0
http.port: 9200-9202

使用“heroku日志”我可以看到:

user@user-X550JF:~/Documents/SOFT/cloudrobe$ sbt stage deployHeroku
Detected sbt version 0.13.9
....
....
[info] Packaging /home/user/Documents/SOFT/cloudrobe/target/scala-2.11/cloudrobe_2.11-0.1.0-SNAPSHOT.war ...
[info] Done packaging.
[success] Total time: 2 s, completed May 25, 2016 1:04:51 AM
[info] -----> Packaging application...
[info]        - app: cloudrobe
[info]        - including: target/universal/stage/
[info] -----> Creating build...
[info]        - file: target/heroku/slug.tgz
[info]        - size: 45MB
[info] -----> Uploading slug... (100%)
[info]        - success
[info] -----> Deploying...
[info] remote: 
[info] remote: -----> Fetching set buildpack https://codon-buildpacks.s3.amazonaws.com/buildpacks/heroku/jvm-common.tgz... done
[info] remote: -----> sbt-heroku app detected
[info] remote: -----> Installing OpenJDK 1.8... done
[info] remote: 
[info] remote: -----> Discovering process types
[info] remote:        Procfile declares types -> web
[info] remote: 
[info] remote: -----> Compressing...
[info] remote:        Done: 93.5M
[info] remote: -----> Launching...
[info] remote:        Released v11
[info] remote:        https://cloudrobe.herokuapp.com/ deployed to Heroku
[info] remote: 
[info] -----> Done
___________________________________________________________________________

但是,5或10秒后出现以下错误,表明连接已超时:

2016-05-24T23:14:16.007200+00:00 app[web.1]: 23:14:16.006 [main] INFO  org.mongodb.driver.connection - Opened connection [connectionId{localValue:5, serverValue:5}] to localhost:33333
2016-05-24T23:14:16.370324+00:00 app[web.1]: 23:14:16.370 [main] INFO  o.f.s.servlet.ServletTemplateEngine - Scalate template engine using working directory: /tmp/scalate-5146893161861816095-workdir
2016-05-24T23:14:16.746719+00:00 app[web.1]: 23:14:16.746 [main] INFO  o.e.j.server.handler.ContextHandler - Started o.e.j.w.WebAppContext@7a356a0d{/,file:/app/src/main/webapp,AVAILABLE}
2016-05-24T23:14:16.782745+00:00 app[web.1]: 23:14:16.782 [main] INFO  o.e.jetty.server.ServerConnector - Started ServerConnector@7dc51783{HTTP/1.1}{0.0.0.0:8080}
2016-05-24T23:14:16.782924+00:00 app[web.1]: 23:14:16.782 [main] INFO  org.eclipse.jetty.server.Server - Started @6674ms

这是我使用端口5000的Procfile:

2016-05-24T23:52:32.962896+00:00 heroku[router]: at=error code=H20 desc="App boot timeout" method=GET path="/" host=cloudrobe.herokuapp.com request_id=a7f68d98-54a2-44b7-8f5f-47efce0f1833 fwd="52.90.128.17" dyno= connect= service= status=503 bytes=
2016-05-24T23:52:45.463575+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch

谢谢。

1 个答案:

答案 0 :(得分:0)

您的应用程序绑定到端口8080,但它需要绑定到Heroku上设置为=QUERY(Worksheet1!A:C,"select A where C <= date '"&text(A2,"yyyy-MM-dd")&"'",0) 环境变量的端口。为此,您需要将$PORT添加到-Dhttp.port=$PORT。它还需要绑定到0.0.0.0而不是127.0.0.1。所以它可能看起来像这样:

Procfile