ラベル SBT の投稿を表示しています。 すべての投稿を表示
ラベル SBT の投稿を表示しています。 すべての投稿を表示

2016年4月26日火曜日

PlayFramework-2.5をHerokuで動かす


基本的にはここに書かれている通りに進めた。: https://www.playframework.com/documentation/ja/2.4.x/ProductionHeroku

herokuツールのインストールおよび、herokuアカウントは取得済みとする。

activatorでプロジェクトの作成

$ activator new プロジェクト名 play-scala
 

git管理化

$ git init
$ git add .
$ git commit -m "initial commit"

herokuプロジェクトの作成

$ heroku create

デプロイ

$ git push heroku master

ここで http://アプリ名.heroku.com/ にアクセスできるはずだがエラーになってしまう。試しに heroku logs でログを見てみると次のようなエラーログが。

 2016-04-25T10:27:14.332916+00:00 app[web.1]: [error] p.a.l.c.CryptoConfigParser - The application secret has not been set, and we are in prod mode. Your application is not secure.
2016-04-25T10:27:14.337915+00:00 app[web.1]: [error] p.a.l.c.CryptoConfigParser - To set the application secret, please read http://playframework.com/documentation/latest/ApplicationSecret
2016-04-25T10:27:14.435785+00:00 app[web.1]: [error] p.a.l.c.CryptoConfigParser - The application secret has not been set, and we are in prod mode. Your application is not secure.
2016-04-25T10:27:14.435967+00:00 app[web.1]: [error] p.a.l.c.CryptoConfigParser - To set the application secret, please read http://playframework.com/documentation/latest/ApplicationSecret
2016-04-25T10:27:14.436789+00:00 app[web.1]: [error] p.a.l.c.CryptoConfigParser - The application secret has not been set, and we are in prod mode. Your application is not secure.
2016-04-25T10:27:14.436985+00:00 app[web.1]: [error] p.a.l.c.CryptoConfigParser - To set the application secret, please read http://playframework.com/documentation/latest/ApplicationSecret


エラーメッセージで検索してみると次の解決策が見つかった。 http://stackoverflow.com/questions/8686394/how-to-keep-the-app-secret-a-secret

conf/application.conf の「play.crypto.secret」の行を次のように修正

play.crypto.secret = ${APP_SECRET}

そして、heroku環境でAPP_SECRETという環境変数が設定されているようにする

$ heroku config:add APP_SECRET=xxxxxxxx

(xxxxxxx)のところに秘密のキーを適当に作って入れる

これで、git pushしたら動くはず
ローカルでstartしたいときのためにローカルでもAPP_SECRETを設定しておく

$ export APP_SECRET=hoge


環境

  • Play framework 2.5.2
  • JDK: java-8-oracle
  • OS: Ubuntu 14.04

2014年12月18日木曜日

play framework 2で「ファイル名が長すぎます」と出た時の対処法

Play Framework 2.1 を使っていた時に次のようなエラーが出たことがあった。
$ play ~compile
...
[error] 
[error]      while compiling: myproject/target/scala-2.10/src_managed/main/views/html/signup.template.scala
[error]         during phase: jvm
[error]      library version: version 2.10.0
[error]     compiler version: version 2.10.0
[error]   reconstructed args: -encoding utf8 -bootclasspath ...
[error] 
[error]   last tree to typer: Literal(Constant(play.api.templates.Html))
[error]               symbol: null
[error]    symbol definition: null
[error]                  tpe: Class(classOf[play.api.templates.Html])
[error]        symbol owners: 
[error]       context owners: anonymous class anonfun$f$1 -> package html
[error] 
[error] == Enclosing template or block ==
...

[error] == Expanded type of tree ==
[error] 
[error] ConstantType(value = Constant(play.api.templates.Html))
[error] 
[error] uncaught exception during compilation: java.io.IOException
[error] ファイル名が長すぎます
[error] two errors found
[error] (compile:compile) Compilation failed
[error] Total time: 25 s, completed 2014/12/18 11:57:36
1. Waiting for source changes... (press enter to interrupt)
どうやら、playが自動生成するファイルのクラス名が長すぎて、scalaコンパイラの扱う長さを超えてしまっていることが原因らしい。しかしscalacに渡すコンパイラオプションを指定することによって長い名前を許容することができる。 play frameworkの場合はSBTを使っているので、project/Build.scalaをつぎのように変更した。

object ApplicationBuild extends Build {
  ...

  val main = play.Project(appName, appVersion, appDependencies).settings(
    scalacOptions ++= Seq("-Xmax-classfile-name", "140")
  )
}
参考: https://github.com/scala/pickling/issues/10#issuecomment-31318136