Using Micro Cloud Foundry from Grails |
|
Back in April, VMware introduced Cloud Foundry to the world and with it came super-simple application deployment for Grails developers. Fast forward several months and now another piece of the jigsaw is in place: Micro Cloud Foundry. You can now have your own Cloud Foundry instance for testing or any other use case. And of course, it's incredibly easy to use from Grails.
So what is Micro Cloud Foundry? The following screencast gives you a brief overview of the product and then takes you through the process of downloading, installing and configuring it. At the end, you get to see how you can deploy a Grails application to your Micro Cloud Foundry instance instead of cloudfoundry.com:
You can learn more about Micro Cloud Foundry and how to set it up in the Cloud Foundry blog post, and if you're an STS user check out Josh Long's blog post and screencast which include info on using STS and Micro Cloud Foundry together. Here, I'll just quickly explain the difference between deploying to cloudfoundry.com and a Micro Cloud Foundry instance from Grails.
Once you have your Micro Cloud Foundry VM up and running with a custom cloudfoundry.me sub-domain, you only require two steps before deploying Grails applications to it:
- install the latest Cloud Foundry plugin for Grails into your application, e.g. with grails install-plugin cloud-foundry; and
- configure the Cloud Foundry credentials and target URL.
That really is it! As soon as the appropriate configuration options are set, you can deploy directly to the Micro Cloud Foundry instance using the cf-push and cf-update commands. And those configuration options? They constitute the username and password for a valid user account on the Micro Cloud Foundry instance (typically created with the vmc register command), and the URL for that instance. This last is simply your custom cloudfoundry.me sub-domain with an 'api.' prefix.
These options can be declared in one of BuildConfig.groovy, $HOME/.grails/settings.groovy, or Config.groovy in that order of precedence. For example, you might have your cloudfoundry.com credentials in your personal settings.groovy file and the override them with values in BuildConfig.groovy:
grails.plugin.cloudfoundry.username = "pedro@mycompany.com" grails.plugin.cloudfoundry.password = "password" grails.plugin.cloudfoundry.target = "api.mycompany.cloudfoundry.me"
Now every Cloud Foundry command you execute will operate against the configured Micro Cloud Foundry instance. What could be easier?
Update [26 Aug 2011] At the time of writing, the latest version of the grailstwitter app depends on RabbitMQ which is not yet available in Micro Cloud Foundry. I have modified the link below to point to an earlier version (commit) that does not use RabbitMQ
Useful links:
Similar Posts
- Rapid Cloud Foundry Deployments with Maven
- Micro Cloud Foundry for Spring Developers
- One-step deployment with Grails and Cloud Foundry
- Cloud Foundry integrated into developer tools
- New Cloud Foundry feature: Save deployment blueprints as Templates





Zach Thomas says:
Added on August 26th, 2011 at 9:25 amThanks, this is really cool!
One edit though: as of this writing, the grailstwitter sample application also uses RabbitMQ, which isn't yet a supported service on the microcloud.
Assuming you're using git to clone the source code, you can get back to a working example like this:
# if you've changed your config properties, you'll want to stash your changes
git stash
git checkout -b without-rabbitmq e2a2bfe8ec4c6a38
git stash pop
Then you'll be able to deploy to your microcloud:
grails prod cf-push
Cheers.
Peter Ledbrook (blog author) says:
Added on August 26th, 2011 at 10:03 amThanks Zach, good catch. I've added a short update and modified the link to the source code.
Joe Atzberger says:
Added on August 30th, 2011 at 2:22 pmLooks like your config lines got escaped inappropriately, i.e. with """.
Joe Atzberger says:
Added on August 30th, 2011 at 2:24 pmHmm… looks like my message did too. Problem is Ampersand-quot; instead of regular quotes.
Peter Ledbrook (blog author) says:
Added on September 12th, 2011 at 4:50 am@Joe Thanks. That happens when updating the post: code samples suddenly end up with the HTML entities. Now corrected.