Grails on Cloud Foundry

Posted by {"display_name"=>"greg", "login"=>"greg", "email"=>"", "url"=>""} on June 27, 2011 · 5 mins read

VMware's new Cloud Foundry PaaS offering was released in beta recently and appears to be a great option for Grails developers. Peter Ledbrook, Grails project developer and co-author of Grails in Action, has written two posts on the subject. The first provides a one step deployment instructions and the second more in depth example of an app that uses both MySQL and MongoDB.

And there's a Grails Plugin for Cloud Foundry that appears to make for simple deployment of Grails apps.

Install CloudFoundry Admin Tool

On receiving my Cloud Foundry sign-up email I downloaded the installation pdf. The current instructions walk through the deployment of a simple Ruby application but never tells you to change your password. I'm not interested in Ruby and just want to change my password and move on to a Grails deployment so I performed the following steps:

$ sudo apt­‐get install ruby­‐full
$ sudo apt-­get install rubygems
$ sudo gem install vmc
$ vmc target
$ vmc login
Password: ********
Successfully logged into []
$ vmc passwd
Changing password for ''
New Password: ********
Verify Password: ********

Now that we've logged in and reset our password, it's time to deploy a grails application. I'm going to choose an application of mine that's in a stable state but that I've only run in development mode.

Install CloudFoundry Plugin for Grails

I'm going to follow Ledbrook's instructions from here. The first step is to install the Cloud Foundry plug-in for Grails:

$ grails install-plugin cloud-foundry

Edit the $HOME/.grails/settings.groovy file and add your credentials. I had to create this file on my

grails.plugin.cloudfoundry.username = ""
grails.plugin.cloudfoundry.password = " "

Verify that your credentials are working with the following command and you should receive a short summary of your account:

$ grails cf-info

Deploy Application to CloudFoundry

Ignoring possible issues with the DataSource.groovy configuration, let's deploy the application directly to Cloud Foundry with this command:

$ grails cf-push

You'll be prompted for your application URL which my or may not be available. I lucked out and my app's existing name was available.

Application Deployed URL: ''?

Would you like to create and bind a mysql service? ([y], n)

Service 'mysql-xxxxxxx' provisioned.

Creating application ipadBackup at with 512MB and services [mysql-xxxxxxx]: OK

Uploading Application:
Checking for available resources: OK
Processing resources: OK
Packing application: OK
Uploading (5M): OK

Trying to start Application: 'ipadBackup'.

Application 'ipadBackup' started.

If the URL is not available, you can override your Grails application name and specify another URL with the --appname option:

grails cf-push --appname=ipadAppUsage


I was surprised to find that my app's web page came up immediately. No MySQL credentials were required and no modifications to DataSource.groovy. Magic!

Almost, I have a hardcoded directory path that I had to change. I corrected the path and executed the following commands to update the application:

$ grails cf-update

Documentation on the Grails Cloud Foundry plug-in can be found here. I'm impressed with the ease of deployment to Cloud Foundry. I think their main issue is capacity.

Update: Aug 23, 2011

I regularly have problems with CloudFoundry when trying to update my application with the cf-update command. I found this support posting helpful and am using the following steps to update the app when CloudFoundry is less than responsive:

$ grails cf-update

When the WAR file is generated make a copy of it while cf-update is trying to upload it to CloudFoundry. When the cf-update fails, execute the vmc update command to push your war file. I'm also running into memory issues with my app (discovered via the 'vmc crashlogs <appname>' command which showed that my app was shutdown for requesting more than 512M of memory

$ cp <appdir>/target/*.war <appdir>/target/myapp.war
$ vmc update <appname>
$ vmc mem <appname>