Showing posts with label play framework. Show all posts
Showing posts with label play framework. Show all posts

@since Wednesday, August 24, 2011

Running Play Framework Application on CloudFoundry

@throws 3 exception(s)
I've been waiting a long time to give CloudFoundry a try. Few minutes after the press release announcement I was on the waiting list, waiting to get my account activated. While waiting (not so long but I just can't sit still without doing/learning something new), I started reading and trying to work with Play Framework. As soon as I got my micro account approved I started my journey of running a Play Framework application on CloudFoundry cloud instance.

I've used Play Framwork v.1.2.2 and CloudFoundry micro VM rc1. I've also used the VMC tools v.0.3.12. I started by taking the introduction application and basically configured it to work on the cloud. I'm sure there are better ways to configure Play but for a very simple configuration, most of the information shown below should be enough.

First of all, it's required to add a dependency to CloudFoundry runtime library to obtain services information, such as MySql connection URL and credentials. This library isn't on Maven Central reposiroty so I had to add a repository to my dependencies.yml configuration file.



After updating my Play application dependencies I was ready to write a PlayPlugin for reading CloudFoundry service information and keep those setting for DBPlugin connection creation. All Play configuration is stored in Play.configuration and can be easily altered if you place your modified plugin prior to other plugins.



To start the CloudFoundryMySqlBootstrap before DBPlugin I simply created a play.plugins file located in the application app folder.



My Play application was ready to be pushed to the cloud. All I needed now is a WAR to deploy.



Got it :-)
Using VMC push command I created and started my Play Framework application and published it.




As show on the browser http://playframework-demo.cloudfoundry.com:


Try it or another Play Framework demo application deployed on http://playframework-contact.cloudfoundry.com/

Disclaimer at the time of writing this post, I'm a VMware employee, not part of the CloudFoundry team, but just to be honest. :-)

EDIT: There's a Play Module now available http://www.playframework.org/modules/cloudfoundry