5

Let's Play in the production environment - Knoldus Blogs

 2 years ago
source link: https://blog.knoldus.com/lets-play-in-the-production-environment/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
Reading Time: 4 minutes

In this blog, we are going to see how to deploy the play framework application. And walks you through steps to create Dockerfile, Build and deploy the application.

We will display a Hello World greeting page. As an outcome.

Introduction

We all use the “sbt run” command to run the application in the development environment. However, we can not use the “run ” command in the production environment. As when a run command executes each request check with the “sbt” if any files have changed. And it impacts your application performance.

There are different ways to deploy the application, But here we see by creating the artifact using dist task.

The artifact can be created using several ways as follows

  • ‘sbt package’ command
  • ‘dist’ task
  • Native packager
  • ‘stage’ task
  • sbt assembly plugin

Using dist task

Note: Before you run the application in a production environment you need to create the application secrete click here

Using the dist task it will create the binary version of your project so that you need only java to install to run. No need or dependency of sbt.

Steps

  1. Build your project artifact by entering ‘sbt dist’ command in your terminal. It will create the .zip artifact of your project in target/universal directory.
knoldus@knoldus-Vostro-15-3568:~/IdeaProjects/play-scala-hello-world-tutorial$ sbt dist
[info] Loading global plugins from /home/knoldus/.sbt/1.0/plugins
[info] Loading settings for project play-scala-hello-world-tutorial-build from plugins.sbt,scaffold.sbt ...
[info] Loading project definition from /home/knoldus/IdeaProjects/play-scala-hello-world-tutorial/project
[info] Loading settings for project root from build.sbt ...
[info] Set current project to play-scala-seed (in build file:/home/knoldus/IdeaProjects/play-scala-hello-world-tutorial/)
[info] Packaging /home/knoldus/IdeaProjects/play-scala-hello-world-tutorial/target/scala-2.12/play-scala-seed_2.12-1.0-SNAPSHOT-sources.jar ...
[info] Done packaging.
[info] Wrote /home/knoldus/IdeaProjects/play-scala-hello-world-tutorial/target/scala-2.12/play-scala-seed_2.12-1.0-SNAPSHOT.pom
[info] Main Scala API documentation to /home/knoldus/IdeaProjects/play-scala-hello-world-tutorial/target/scala-2.12/api...
[info] Packaging /home/knoldus/IdeaProjects/play-scala-hello-world-tutorial/target/scala-2.12/play-scala-seed_2.12-1.0-SNAPSHOT.jar ...
[info] Done packaging.
model contains 19 documentable templates
[info] Main Scala API documentation successful.
[info] Packaging /home/knoldus/IdeaProjects/play-scala-hello-world-tutorial/target/scala-2.12/play-scala-seed_2.12-1.0-SNAPSHOT-javadoc.jar ...
[info] Done packaging.
[warn] [1] The maintainer is empty
[warn] Add this to your build.sbt
[warn]   maintainer := "[email protected]"
[success] All package validations passed
[info] Your package is ready in /home/knoldus/IdeaProjects/play-scala-hello-world-tutorial/target/universal/play-scala-seed-1.0-SNAPSHOT.zip
[success] Total time: 12 s, completed 12 Feb, 2020 11:33:34 PM
knoldus@knoldus-Vostro-15-3568:~/IdeaProjects/play-scala-hello-world-tutorial$ 

2. Extract the zip folder using unzip command. It unzips the folder in the same directory where the zip artifact is.

knoldus@knoldus-Vostro-15-3568:~/IdeaProjects/play-scala-hello-world-tutorial$ unzip target/universal/play-scala-seed-1.0-SNAPSHOT.zip
Archive:  target/universal/play-scala-seed-1.0-SNAPSHOT.zip
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/com.example.play-scala-seed-1.0-SNAPSHOT-sans-externalized.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/org.scala-lang.scala-library-2.12.8.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/com.typesafe.play.twirl-api_2.12-1.4.0.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/org.scala-lang.modules.scala-xml_2.12-1.1.0.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/com.typesafe.play.play-server_2.12-2.7.0.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/com.typesafe.play.play_2.12-2.7.0.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/com.typesafe.play.build-link-2.7.0.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/com.typesafe.play.play-exceptions-2.7.0.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/com.typesafe.play.play-streams_2.12-2.7.0.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/org.reactivestreams.reactive-streams-1.0.2.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/com.typesafe.akka.akka-stream_2.12-2.5.19.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/com.typesafe.akka.akka-actor_2.12-2.5.19.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/com.typesafe.config-1.3.3.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/org.scala-lang.modules.scala-java8-compat_2.12-0.9.0.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/com.typesafe.akka.akka-protobuf_2.12-2.5.19.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/com.typesafe.ssl-config-core_2.12-0.3.7.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/org.scala-lang.modules.scala-parser-combinators_2.12-1.1.1.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/org.slf4j.slf4j-api-1.7.25.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/org.slf4j.jul-to-slf4j-1.7.25.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/org.slf4j.jcl-over-slf4j-1.7.25.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/com.typesafe.akka.akka-slf4j_2.12-2.5.19.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/com.fasterxml.jackson.core.jackson-core-2.9.8.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/com.fasterxml.jackson.core.jackson-annotations-2.9.8.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/com.fasterxml.jackson.core.jackson-databind-2.9.8.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/com.fasterxml.jackson.datatype.jackson-datatype-jdk8-2.9.8.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/com.fasterxml.jackson.datatype.jackson-datatype-jsr310-2.9.8.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/com.typesafe.play.play-json_2.12-2.7.0.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/com.typesafe.play.play-functional_2.12-2.7.0.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/org.scala-lang.scala-reflect-2.12.8.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/org.typelevel.macro-compat_2.12-1.1.1.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/org.scala-lang.modules.scala-collection-compat_2.12-0.1.1.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/joda-time.joda-time-2.10.1.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/com.google.guava.guava-27.0-jre.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/com.google.guava.failureaccess-1.0.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/com.google.guava.listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/com.google.code.findbugs.jsr305-3.0.2.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/org.checkerframework.checker-qual-2.5.2.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/com.google.errorprone.error_prone_annotations-2.2.0.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/com.google.j2objc.j2objc-annotations-1.1.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/org.codehaus.mojo.animal-sniffer-annotations-1.17.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/io.jsonwebtoken.jjwt-0.9.1.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/javax.xml.bind.jaxb-api-2.3.1.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/javax.activation.javax.activation-api-1.2.0.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/javax.transaction.jta-1.1.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/javax.inject.javax.inject-1.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/com.typesafe.play.play-logback_2.12-2.7.0.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/ch.qos.logback.logback-classic-1.2.3.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/ch.qos.logback.logback-core-1.2.3.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/com.typesafe.play.play-akka-http-server_2.12-2.7.0.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/com.typesafe.akka.akka-http-core_2.12-10.1.7.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/com.typesafe.akka.akka-parsing_2.12-10.1.7.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/com.typesafe.play.filters-helpers_2.12-2.7.0.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/com.typesafe.play.play-guice_2.12-2.7.0.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/com.google.inject.guice-4.2.2.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/aopalliance.aopalliance-1.0.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/com.google.inject.extensions.guice-assistedinject-4.2.2.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/lib/com.example.play-scala-seed-1.0-SNAPSHOT-assets.jar  
  inflating: play-scala-seed-1.0-SNAPSHOT/bin/play-scala-seed  
  inflating: play-scala-seed-1.0-SNAPSHOT/bin/play-scala-seed.bat  
  inflating: play-scala-seed-1.0-SNAPSHOT/conf/logback.xml  
  inflating: play-scala-seed-1.0-SNAPSHOT/conf/application.conf  
  inflating: play-scala-seed-1.0-SNAPSHOT/conf/messages  
  inflating: play-scala-seed-1.0-SNAPSHOT/conf/routes  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/open-sans-v13-latin-700.woff  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/abstract_type.svg  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/package.svg  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/MaterialIcons-Regular.eot  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/jquery.panzoom.min.js  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/lato-v11-latin-100.eot  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/object_comp_trait.svg  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/open-sans-v13-latin-regular.ttf  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/index.js  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/open-sans-v13-latin-700.ttf  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/lato-v11-latin-regular.ttf  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/class_diagram.png  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/trait_comp.svg  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/open-sans-v13-latin-700.eot  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/ownerbg.gif  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/source-code-pro-v6-latin-regular.eot  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/object_diagram.png  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/object.svg  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/open-sans-v13-latin-400i.ttf  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/source-code-pro-v6-latin-700.woff  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/class_comp.svg  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/diagrams.js  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/open-sans-v13-latin-400i.eot  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/lato-v11-latin-regular.woff  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/source-code-pro-v6-latin-700.ttf  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/type_diagram.png  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/jquery.js  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/ref-index.css  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/ownderbg2.gif  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/tools.tooltip.js  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/open-sans-v13-latin-700i.ttf  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/open-sans-v13-latin-400i.woff  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/ownerbg2.gif  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/open-sans-v13-latin-700i.eot  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/source-code-pro-v6-latin-regular.woff  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/open-sans-v13-latin-regular.woff  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/index.css  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/modernizr.custom.js  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/jquery.mousewheel.min.js  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/trait_diagram.png  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/open-sans-v13-latin-700i.woff  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/MaterialIcons-Regular.ttf  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/source-code-pro-v6-latin-700.eot  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/template.js  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/MaterialIcons-Regular.woff  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/lato-v11-latin-100.ttf  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/source-code-pro-v6-latin-regular.ttf  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/class.svg  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/lato-v11-latin-100.woff  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/template.css  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/object_comp.svg  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/lato-v11-latin-regular.eot  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/trait.svg  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/scheduler.js  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/open-sans-v13-latin-regular.eot  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/lib/diagrams.css  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/index.js  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/controllers/routes.html  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/controllers/ReverseHomeController.html  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/controllers/javascript/ReverseHomeController.html  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/controllers/javascript/ReverseAssets.html  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/controllers/javascript/index.html  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/controllers/HomeController.html  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/controllers/ReverseAssets.html  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/controllers/index.html  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/router/RoutesPrefix$.html  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/router/Routes.html  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/router/index.html  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/index.html  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/views/html/commonSidebar$.html  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/views/html/explore$.html  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/views/html/index$.html  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/views/html/tutorial$.html  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/views/html/index.html  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/views/html/main$.html  
  inflating: play-scala-seed-1.0-SNAPSHOT/share/doc/api/views/index.html  
  inflating: play-scala-seed-1.0-SNAPSHOT/README.md 

3. After creating extracting the zip artifact run the script file present in bin directory. There are two versions of script present

  • 1 bash shell script(Linux, Ubuntu)
  • 2 .bat(is present for windows)
./target/universal/play-scala-seed-1.0-SNAPSHOT/bin/play-scala-seed 
Oops, cannot start the server.
Configuration error: Configuration error[
The application secret has not been set, and we are in prod mode. Your application is not secure.
To set the application secret, please read http://playframework.com/documentation/latest/ApplicationSecret
          ]
	at play.api.Configuration$.configError(Configuration.scala:158)
	at play.api.Configuration.reportError(Configuration.scala:992)
	at play.api.http.HttpConfiguration$.getSecretConfiguration(HttpConfiguration.scala:280)
	at play.api.http.HttpConfiguration$.fromConfiguration(HttpConfiguration.scala:266)
	at play.api.http.HttpConfiguration$HttpConfigurationProvider.get$lzycompute(HttpConfiguration.scala:354)
	at play.api.http.HttpConfiguration$HttpConfigurationProvider.get(HttpConfiguration.scala:354)
	at play.api.http.HttpConfiguration$HttpConfigurationProvider.get(HttpConfiguration.scala:353)
	at com.google.inject.internal.ProviderInternalFactory.provision(ProviderInternalFactory.java:85)
	at com.google.inject.internal.BoundProviderFactory.provision(BoundProviderFactory.java:77)
	at com.google.inject.internal.ProviderInternalFactory.circularGet(ProviderInternalFactory.java:59)
	at com.google.inject.internal.BoundProviderFactory.get(BoundProviderFactory.java:61)
	at com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:42)
	at com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterInjector.java:65)
	at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:113)
	at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:91)
	at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:306)
	at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
	at com.google.inject.internal.SingletonScope$1.get(SingletonScope.java:168)
	at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:39)
	at com.google.inject.internal.BoundProviderFactory.get(BoundProviderFactory.java:60)
	at com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:42)
	at com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterInjector.java:65)
	at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:113)
	at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:91)
	at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:306)
	at com.google.inject.internal.FactoryProxy.get(FactoryProxy.java:62)
	at com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:42)
	at com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterInjector.java:65)
	at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:113)
	at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:91)
	at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:306)
	at com.google.inject.internal.FactoryProxy.get(FactoryProxy.java:62)
	at com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:42)
	at com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterInjector.java:65)
	at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:113)
	at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:91)
	at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:306)
	at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
	at com.google.inject.internal.SingletonScope$1.get(SingletonScope.java:168)
	at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:39)
	at com.google.inject.internal.FactoryProxy.get(FactoryProxy.java:62)
	at com.google.inject.internal.InternalInjectorCreator.loadEagerSingletons(InternalInjectorCreator.java:211)
	at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:182)
	at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:109)
	at com.google.inject.Guice.createInjector(Guice.java:87)
	at com.google.inject.Guice.createInjector(Guice.java:78)
	at play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:186)
	at play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:139)
	at play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21)
	at play.core.server.ProdServerStart$.start(ProdServerStart.scala:57)
	at play.core.server.ProdServerStart$.main(ProdServerStart.scala:29)
	at play.core.server.ProdServerStart.main(ProdServerStart.scala)

Now here you can see it shows the error if I am not providing the application secrete. So it is necessary to provide the application secrete when running in the production environment.

4. Run using the following command

sbt -Dplay.http.secret.key=ad31779d4ee49d5ad5162bf1429c32e2e9933f3b
[info] play.api.Play - Application started (Prod) (no global state)
[info] p.c.s.AkkaHttpServer - Listening for HTTP on /0:0:0:0:0:0:0:0:9000

Now here the application is running successfully and you see the output by bowsing the localhost:9000

Containerized a play application

  1. Copy all the above steps in a Dockerfile(Create a Dockerfile)

Dockerfile

FROM openjdk:8-jre-alpine
WORKDIR /play-scala-hello-world
RUN apk --no-cache add bash
RUN ls -a
COPY ./target/universal/play-scala-seed-1.0-SNAPSHOT.zip .
RUN ls -a
RUN unzip play-scala-seed-1.0-SNAPSHOT && rm play-scala-seed-1.0-SNAPSHOT.zip
CMD ./play-scala-seed-1.0-SNAPSHOT/bin/play-scala-seed -Dplay.http.secret.key='QCY?tAnfk?aZ?iwrNwnxIlR6CTf:G3gf:90Latabg@5241AB`R5W:1uDFN];Ik@n'

Here we use base image of OpenJDK , which we already stated we only need java.

2. Build Dockerfile ( it creates an image with the tag you provided)

sudo docker build -t play-scala-application .
Sending build context to Docker daemon  152.6MB
Step 1/8 : FROM openjdk:8-jre-alpine
 ---> f7a292bbb70c
Step 2/8 : WORKDIR /play-scala-hello-world
 ---> Using cache
 ---> d2f45b7b811a
Step 3/8 : RUN apk --no-cache add bash
 ---> Using cache
 ---> edb71c68854c
Step 4/8 : RUN ls -a
 ---> Using cache
 ---> 56f1fafe96c1
Step 5/8 : COPY ./target/universal/play-scala-seed-1.0-SNAPSHOT.zip .
 ---> Using cache
 ---> 548a68e718cc
Step 6/8 : RUN ls -a
 ---> Using cache
 ---> cc0f914070fa
Step 7/8 : RUN unzip play-scala-seed-1.0-SNAPSHOT && rm play-scala-seed-1.0-SNAPSHOT.zip
 ---> Using cache
 ---> dbaea0dbfa2a
Step 8/8 : CMD ./play-scala-seed-1.0-SNAPSHOT/bin/play-scala-seed -Dplay.http.secret.key='QCY?tAnfk?aZ?iwrNwnxIlR6CTf:G3gf:90Latabg@5241AB`R5W:1uDFN];Ik@n'
 ---> Using cache
 ---> a88bcc5f0591
Successfully built a88bcc5f0591
Successfully tagged play-scala-application:latest

3. Run the image on the port 9000 as the play by defaults run on 9000 port.

sudo docker run -p 9000 play-scala-application:latest
[info] play.api.Play - Application started (Prod) (no global state)
[info] p.c.s.AkkaHttpServer - Listening for HTTP on /0.0.0.0:9000

4. Open localhost:9000 (you will see->)

In this example we created the zip artifact f the project, we can also create the jar artifact. Learn how to create .jar Here


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK