It is very easy to create a docker image of a scala play app using sbt, which can then be uploaded to AWS EC2 or Elastic Beanstalk
Using the command line:
This will generate a docker image in target/docker, with a file called ‘Dockerfile’ and a directory called ‘files’. In Dockerfile, you will need to append the following line: EXPOSE 9000. You may also want to add any parameters to the line ENTRYPOINT. For example, I added a parameter for loading the production configuration file.
1 2 3 4 5 6 7 8 9
You will also need to create a file called Dockerrun.aws.json. It goes at the same level as Dockerfile.
1 2 3 4 5 6
Once those are created, you can zip the files and then upload it to elastic beanstalk. Caution, you must not zip the parent ‘docker’ directory. Dockerfile, Dockerrun.aws.json, and files need to be in the root. For example, in terminal, navigate to target/docker and run
Automated Deployment with Jenkins
Best practice is to have a continuous integration server automatically deploy to a staging environment. Below is a bash script that can be used in Jenkins to automatically test, build and deploy to elastic beanstalk. It uses the git revision as the application version.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25