Skip to content

Instantly share code, notes, and snippets.

@co-sche
Last active March 31, 2023 05:24
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save co-sche/7ec17875f324a54d695b to your computer and use it in GitHub Desktop.
Save co-sche/7ec17875f324a54d695b to your computer and use it in GitHub Desktop.
AWS Elastic Beanstalk (Java8)に最小手順でPlay Framework (Scala)のアプリをデプロイする

sbt dist

これだけで${PROJECT_ROOT}/target/universal/に起動スクリプトなどを含んだパッケージ(zip)が生成される。

内部でsbt-native-packagerが呼ばれる。

これは一応プラグインだけど、今のPlayではビルトインなので、addSbtPluginする必要はない。

けど、まだEBでそのままデプロイできるパッケージではない。

Procfile

EBで実行するには、上記で生成されるパッケージの最上位にエントリーポイントとなるProcfileが必要。

中身は、

web: sh bin/${YOUR_SCRIPT} -Dhttp.port=5000

これだけ。

  • ${YOUR_SCRIPT}は、パッケージ内のbin/にある起動スクリプト名を記述。
  • portが5000番なのは、EB(java8)がnginxを含んでいて、それのフォワード先が5000番だから。別にNginx側を変えてもいい。

build.sbt

上のProcfileを適当なところに置いておき、それをパッケージに含めるための設定を行う。 例えば、${PROJECT_ROOT}/files/Procfileに置いたとすると、

mappings in Universal += file("files/Procfile") -> "Procfile"

これをbuild.sbtに追記する。

もう一度 sbt dist

これで${PROJECT_ROOT}/target/universal/にProcfileを含んだzipが生成されるはず。 確認のために、解凍してみるといい。

あとはEBにできたzipをアップロード、デプロイするだけ。

まとめ

cd ${PROJECT_ROOT}
echo 'web: sh bin/${YOUR_SCRIPT} -Dhttp.port=5000' > ./files/Procfile
echo 'mappings in Universal += file("files/Procfile") -> "Procfile"' >> ./build.sbt
sbt dist

以上。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment