CloudBees includes first-class support for running Play! applications in the Cloud.
To get "git push" style deployment, run the clickstart that sets up the above in one click. This will set up a play 2.1.1 starter app (we try to keep it up to date - easy to update) websocket ready, with a play/sbt build/test.
For those who want to deploy via other means, or want to know more, please do read on. CloudBees runs play2 dists "natively".
Once the application has been created you can use the play command again to enter the Play 2.0 console . You can then use the start command to launch your application for local development.
The best way to deploy your Play2 application to CloudBees is to export the application as a Play Distribution file and then deploy the app with our Play2 ClickStack. This is what is used by the Play2 Clickstart currently for you:
Alternatively, you may also stage, zip your project directory and then deploy, it's up to you and the ClickStack will sniff the contents of the zip file to know how to handle your application.
The SBT plugin is an easy way to deploy Play2 apps onto CloudBees from within the play console. It is also very simple to configure.
Add the following to project/plugins.sbt
Then project Build.scala
import cloudbees.Plugin._
//...
//...
val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA)
.settings(cloudBeesSettings :_*)
.settings(
CloudBees.applicationId := Some("<applicationname>")
)
We need the api key/secret for the CloudBees platform. If you have used the CloudBees SDK before, this will be populated for you already. If not, then create ~/.bees/bees.config and add the following (You can get the secret and key from Grandcentral)
Once you have this, run play cloudbees-deploy from your app folder.
If you want to deploy your play app with a different configuration file, you can use the following command:
Where CONFIG_NAME is the base name (without .conf) of the file in your conf directory.
The Play2 clickstart currently uses our Play2 ClickStack, which is handling Play2 apps natively - see below for how to customise it after you have launched it.
With Play2 - you will probably want to use websockets - you can with cloudbees.
To enable you will need the CloudBees SDK:
You only need to do this once.
The CloudBees database service can be used from your play application, by doing the following:
Your configuration should look like this:
The MySQL driver will also be needed, add this to your project Build.scala config:
You then set your database name, password etc via: bees config:set DB_USER=user here - so you don't have to store passwords in your config.
Note you can also bind databases to an application (and other things, like MongoDB) via bindings which will provide environment variables you can refer to in your config, as an alternative approach.
[Learn more about using CloudBees Databases]
MongoDB
CloudBees offer MongoDB via the mongohq hosted service (along with many other services).
Firstly - pick a plan and subscribe. The free one is fine.
Then create a database (either from the UI, or with the command below):
You can then use this database in your application.
You can use the CloudBees SDK and the "bees config:set" commands to set name value pairs that will be provided to your application at runtime (they are stored encrypted). To access these - you can use ${var_name} in your application.conf file - just like environment variables.
Play allows you to load an alternative configuration using a -Dconfig.resource=CONF_FILENAME system property. You app will then look for the alternative configuration file in the application classpath (you usually provide these alternative configuration files into your application conf/ directory before packaging).
To customize this value on CloudBees, you can use the Bees SDK:
Note: you'll need to restart your app for this config param to be applied
If you want to have your application run in a "private mode" where only those with the password can access it (ie, during development) - you can use the Global interceptor here - simply copy that into your controllers directory and follow the instructions.
Play applications run on CloudBees in production mode - using the "dist" packaged version of the Play application. If you have files in your project, you need to know to load them from the classpath not from the "getFile" methods - those getFile methods may work in development time, but in production play apps, the files will not be there.
For example, if you have a file called "mydata.json" in the conf directory, you access that as follows:
Note it stores the file in the root of the classpath (no "conf" item).
If you want this done quickly with one click - launch the clickstart - see the button to the left ! Click it ! it will set up all of the below for you, but if you like to set things up by hand, read on:
Click on the Builds link in the toolbar to open your Jenkins instance, create a free style job and add your source repository.
For the job you need to add an "Execute script" build step, with the following command.
This will download the version of play you use, and run your tests.
CloudBees expects that logs will be printed to STDOUT it is a good idea to add the following to conf/logger.xml
You can use Jenkins Cloudbees Deployer plugin to deploy continuously your play2 application. You'll the have to configure sbt build step to call the "dist" task, and setup the deployer with "first match" web application pattern set to dist/*.zip.
If you are after version 1 support, see here