為了將 Play Framefork 打包成 Docker image,這邊會使用到 sbt-native-packager,以下附上懶人包。
Code
build.sbt
maintainer in Docker := "Rammus Xu" |
Build and Deploy
Build docker image and test in local.
sbt docker:publishLocal |
Push to GitLab registry.
docker login registry.gitlab.com |
Run Freemium, Download from gitlab.com
docker login registry.gitlab.com |
因為我們有使用 Swagger plugin,所以可以直接使用瀏覽器打開 http://localhost:9002/docs/swagger-ui/index.html?url=/assets/swagger.json
Reference
sbt-native-packager http://www.scala-sbt.org/sbt-native-packager/formats/docker.html
docker 容器的网络模式 http://cizixs.com/2016/06/12/docker-network-modes-explained
GitLab CI: Deployment & Environments https://about.gitlab.com/2016/08/26/ci-deployment-and-environments/
SBT Docker Plugin http://www.scala-sbt.org/sbt-native-packager/formats/docker.html
Play Deploying 2.5 https://www.playframework.com/documentation/2.5.x/Deploying#running-a-production-server-in-place
Troubleshooting
sbt docker:stage 不會更新 swagger
https://github.com/iheartradio/play-swagger/issues/114
需要在 docker:stage append swagger
(stage in Docker) <<= (stage in Docker).dependsOn(swagger) |