├── project ├── build.properties └── plugins.sbt ├── Dockerfile ├── LICENSE └── README.md /project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=0.13.15 2 | -------------------------------------------------------------------------------- /project/plugins.sbt: -------------------------------------------------------------------------------- 1 | // The Play plugin 2 | addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.2") 3 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM anapsix/alpine-java:jdk8 2 | MAINTAINER Tianhao Li 3 | 4 | ENV SBT_VERSION 0.13.15 5 | ENV CHECKSUM 18b106d09b2874f2a538c6e1f6b20c565885b2a8051428bd6d630fb92c1c0f96 6 | 7 | # Install sbt 8 | RUN apk add --update bash curl openssl ca-certificates && \ 9 | curl -L -o /tmp/sbt.zip \ 10 | https://dl.bintray.com/sbt/native-packages/sbt/${SBT_VERSION}/sbt-${SBT_VERSION}.zip && \ 11 | openssl dgst -sha256 /tmp/sbt.zip \ 12 | | grep ${CHECKSUM} \ 13 | || (echo 'shasum mismatch' && false) && \ 14 | mkdir -p /opt/sbt && \ 15 | unzip /tmp/sbt.zip -d /opt/sbt && \ 16 | rm /tmp/sbt.zip && \ 17 | chmod +x /opt/sbt/sbt/bin/sbt && \ 18 | ln -s /opt/sbt/sbt/bin/sbt /usr/bin/sbt && \ 19 | rm -rf /tmp/* /var/cache/apk/* 20 | 21 | # Prebuild with sbt 22 | COPY . /tmp/build/ 23 | 24 | # sbt sometimes failed because of network. retry 3 times. 25 | RUN cd /tmp/build && \ 26 | (sbt compile || sbt compile || sbt compile) && \ 27 | (sbt test:compile || sbt test:compile || sbt test:compile) && \ 28 | rm -rf /tmp/build 29 | 30 | CMD ["sbt"] 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Tianhao Li 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Scala and Play framework Docker Image 2 | 3 | ## Introduction 4 | 1. Dockerhub: [ysihaoy/scala-play](https://hub.docker.com/r/ysihaoy/scala-play/) 5 | 2. Docker image for Scala, Play framework and SBT project with different versions 6 | 7 | ## Supported tags (combinations of Scala, Play and SBT) and Dockerfile links 8 | * 2.12.3-2.6.2-sbt-0.13.15, 9 | [Dockerfile](https://github.com/ysihaoy/docker-scala-play/blob/2.12.3-2.6.2-sbt-0.13.15/Dockerfile) 10 | 11 | * 2.12.2-2.6.0-sbt-0.13.15, [Dockerfile](https://github.com/ysihaoy/docker-scala-play/blob/2.12.2-2.6.0-sbt-0.13.15/Dockerfile) 12 | 13 | * 2.11.8-2.5.4-sbt-0.13.11, [Dockerfile](https://github.com/ysihaoy/docker-scala-play/blob/2.11.8-2.5.4-sbt-0.13.11/Dockerfile) 14 | 15 | * 2.11.7-2.4.6-sbt-0.13.8, [Dockerfile](https://github.com/ysihaoy/docker-scala-play/blob/2.11.7-2.4.6-sbt-0.13.8/Dockerfile) 16 | 17 | ## How to use in your Scala SBT project 18 | 1. Choose a image tag, e.g `2.12.3-2.6.2-sbt-0.13.15` is highly recommended instead of `latest` version 19 | 20 | 2. Sample of your minimal project structure 21 | 22 | ``` 23 | your-play-project 24 | │ build.sbt 25 | │ Dockerfile 26 | │ 27 | ├───project 28 | | build.properties 29 | | plugins.sbt 30 | | 31 | ├───app 32 | │ │ ... 33 | | 34 | └───test 35 | ``` 36 | 37 | 3. Sample of your `Dockerfile` should be like: 38 | 39 | ``` 40 | FROM ysihaoy/scala-play:2.12.2-2.6.0-sbt-0.13.15 41 | 42 | # caching dependencies 43 | COPY ["build.sbt", "/tmp/build/"] 44 | COPY ["project/plugins.sbt", "project/build.properties", "/tmp/build/project/"] 45 | RUN cd /tmp/build && \ 46 | sbt compile && \ 47 | sbt test:compile && \ 48 | rm -rf /tmp/build 49 | 50 | # copy code 51 | COPY . /root/app/ 52 | WORKDIR /root/app 53 | RUN sbt compile && sbt test:compile 54 | 55 | EXPOSE 9000 56 | CMD ["sbt"] 57 | ``` 58 | 59 | ## Optimisation of the build time 60 | In order to have fast CI (continuous integration) build process, sample of your `project/build.properties`, `project/plugins.sbt` and `build.sbt` should be like: 61 | 1. `project/build.properties` 62 | ``` 63 | sbt.version = 0.13.15 64 | ``` 65 | 66 | 2. `project/plugins.sbt` 67 | ``` 68 | // The Play plugin 69 | addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.0") 70 | ``` 71 | 72 | 3. `build.sbt` 73 | ``` 74 | scalaVersion := "2.12.2" 75 | ``` 76 | 77 | ## Note: Since `activator` was EOL-ed on May 24, 2017, instead of using the Activator command, make sure you have sbt 0.13.13 (or higher), and use the “sbt new” command, providing the name of the template. Click [here](https://www.lightbend.com/community/core-tools/activator-and-sbt) to see more. 78 | 79 | ## Happy hacking Scala, Play framework and Docker 80 | --------------------------------------------------------------------------------