Sunday, April 7, 2013

Play Framework 2.x on Windows Azure

Today I am going about setting up a Play Framework 2.1 Scala based project on Windows Azure.

First, signup for a free 90 day windows azure account at https://account.windowsazure.com/signup?offer=ms-azr-0018p

Second setup eclipse with the windows azure deployment plugin.  Use eclipse's Install New Software and enter http://dl.msopentech.com/eclipse for the url.  If you don't have azure sdk 1.8 installed it will be automatically installed when you select new Windows Azure Deployment project in eclipse.  It may take a while as the .Net framework 4.0 will be installed also.  A guide is available at http://msdn.microsoft.com/en-us/library/windowsazure/hh694271.aspx.

Third, setup new azure deployment project in eclipse.  I downloaded publish settings from my azure account and saved locally, then pointed the eclipse plugin to it.  A project was setup with a sample war file, various deployment scripts.  Once deployed, the cloud service was setup on azure automatically and the application deployed.  The first deployment is taking a while so we'll see if it finished.  Presumably the app will be available at http://playtest.cloudapp.net/

Unfortunately the deployment never finished.  I was however able to goto the manage azure portal and upload the deployment.  It asks for 2 things the "package" and the "configuration".  Both of these are found in the deploy directory of the azure deployment project (WindowsAzurePackage.cspkg and ServiceConfiguration.cscfg respectively).  Select them and click the check mark to begin the upload.  After a while (~ 20 minites) the application finish uploading and begin deployment.  Once that's complete you can access the app.  My example is at http://tomcattest2.cloudapp.net/HelloWorld/

Now, looking that the WorkerRole1 directory, I noticed the artifacts are in there -- jdk, tomcat war file.  So what if instead of a war file I have a play dist zip?  And further, what if the start.cmd didn't run catcline_home/startup.cmd but ran a java command to run the play app.  So I created new play app (play new play2Test) and then created a dist (play dist).  Then in the WorkerRole1\approot\start.cmd I added

start java -cp ".\play2test-1.0-SNAPSHOT\lib\*" play.core.server.NettyServer .

where play2test-1.0-SNAPSHOT is the dist of my empty play app.

Lastly, I updated the worker role components - right click the worker role and select properties/components.  I removed HelloWorld.war file and added my dist.  Told the worker to unzip it in the approot directory so that my java command above would find all the jars and run the app.  I tested locally using the azure emulator and it worked.  I also changed the endpoints to map port 80 to port 9000 the default netty port for play apps.






Then I began the deploy to cloud step which rebuilds the deployment for cloud instead of local and stopped it after the build was complete and the deployment had begun.  Then went to azure management portal and manually uploaded.  With any luck the app will be available at http://play2test.cloudapp.net/.