Google App Engine Standard EnvironmentにScalaで書いたWebアプリケーションをデプロイ

してみた: GitHub - aereal/gae-scala

GAE SE (Google App Engine Standard Environment) のいわゆる2nd generationと呼ばれるgVisorで構築された世代でJava 8/11が使える。

GAE SE (Google App Engine Standard Environment) ではgVisor上で実行されるランタイムとして新たにJava 8/11が選べる。

※当初Java 8を含めて2nd gen.としていたが公式ドキュメントによるとJava 8はgVisorで仮想化されているが、世代としてはJava 11のみが2nd gen.だったので訂正します。

Second generation runtimes are: Python 3.7, Java 11, Node 8, Node 10 PHP 7.2, PHP 7.3, Ruby 2.5, Go 1.11, and Go 1.12.

The App Engine Standard Environment  |  App Engine Documentation  |  Google Cloud

かつ、Serveletに対応しているJVM言語なら基本なんでも動くっぽく、公式のサンプルではKotolinの例もあった
https://github.com/GoogleCloudPlatform/getting-started-java/tree/master/appengine-standard-java8

古いJava 7ランタイムとの詳しい違いは以下:

The App Engine Java 8 runtime, which is based on OpenJDK 8, supports all of the existing features available in the current Java 7 runtime, which is based on OpenJDK 7, but with the following upgrades and enhancements:

  • Doesn't impose a security manager as the Java 7 runtime does, which means your code won't be restricted by Java permissions issues.
  • Supports all the standard public Java libraries.
  • Uses Jetty 9
  • Supports the Java Servlet 3.1 and Java Servlet 2.5 specifications.
  • Supports all Google Cloud-based APIs accessible from the Google Cloud Client Library for Java.
Java 8 Runtime Environment  |  App Engine standard environment for Java 8  |  Google Cloud

で、Scalaも動きそうだったので試した。

やったことは:

  • Scalaなのでmvnではなくsbtを使いたいのでsbt-appengineを入れる
  • GAEと関係ないけどScala 2.13にしたかったのでScalatra 2.7 RC1にした
    • ドキュメントに書いてある依存ライブラリのバージョンだと古くて2.13に対応していなかったりするので適宜上げたりした
  • Homebrewで入れたApp Engine SDK for Javaのどこにパスを遠したらいいかわからなかったけど `libexec` が正解だった

元気に動いています: https://gae-scala-247510.appspot.com

Serveletに対応していないとだめなのでPlayは動かなさそう。
こういう時はScalaでもWSGI/Rack的なやつがはやく策定・普及するといいですね〜〜って思う。