User:Sn1per/Play on Tool Labs

From Wikitech
Jump to navigation Jump to search

Congratulations, you want to learn Scala/Java. Here's how to set up a Play framework project on Tool Labs. I'm using IntelliJ IDEA.

  1. Open up IntelliJ IDEA (or whatever IDE you use) and make a new project. In IntelliJ (not sure about other IDEs) you can specify you want a Play project, and the IDE will generate a basic project.
  2. Build and run it to make sure it works.
  3. Change the Play configuration to fit Tool Labs.
    # Secret key
    # ~~~~~
    # The secret key is used to secure cryptographics functions.
    # If you deploy your application to several instances be sure to use the same key!
    # On Tool Labs, we will make a startup script that specifies play.crypto.secret
    # using a command line option reading from a private file.
    # Port
    # ~~~~~
    # On WMF Tool Labs, the port used by kubernetes webservice is 8000/TCP
    # Disable PID file
    # ~~~~
    # On Tool Labs, you do not need a PID file, since only one instance of the server runs in a container.
    # A PID file prevents the instance from restarting properly if Play crashes for whatever reason (which it seems to do after extended periods of time).
    pidfile.path = "/dev/null"
    # HTTP context
    # ~~~~~
    # Your tool will be available at$TOOLNAME/.
    # Play usually expects to be operating at the root of a domain, so this setting is
    # required for routes to work properly.
  4. Create a Tool Labs project. If you haven't set up your Tool Labs logins and what not, see here.
  5. Become your project, put this project on Github, and then clone it onto Tool Labs (or get it onto your Tool Labs project somehow). Remember that Tool Labs projects should be open source.
  6. If you're using Scala, download the latest version of sbt because the version on Tool Labs is too old. I know that at least 0.3.11 will work with Play 2.5.4 as of July 2016.
    $ cd ~
    $ wget
    $ unzip
    $ rm
    You now have a good version of sbt in ~/sbt/bin/sbt.
  7. To build your project (at the moment, JDK 8 is only available within a Kubernetes pod), use webservice --backend kubernetes jdk8 shell to get a shell that has JDK 8.
    $ cd $PROJECT # go into your Play project directory
    $ ~/sbt/bin/sbt clean stage # or the Play activator, but you'll need to download Play similar to sbt
    Your Play project should be built inside $PROJECT/target/universal/stage/.
  8. Decide on an application secret. Don't share it. Make a file at ~/app_secret and make that string the only contents of that file.
  9. Make the file secret: chmod 440 ~/app_secret
  10. Now we can set up the webservice, using webservice --backend=kubernetes jdk8 start '/data/project/$TOOLNAME/$PROJECT/target/universal/stage/bin/$PROJECT -Dplay.crypto.secret="$(cat /data/project/$TOOLNAME/app_secret)"'. You can put this command in a shell script for convenience.
  11. After rebuilding your application with webservice shell, you can then restart it by issuing webservice restart.