I was lucky enough to get access to cloud foundry. I have heard a lot about how easy it is to deploy a grails app on cloudfoundry. I had to try it myself and here is my experience trying to do so….
Building An App
Lets just create a simple grails app called “HelloCloudFoundry”. to do so, we can create a grails app by running the “grails create-app” command like follows:
/home/manijshrestha/workspace/$grails create-app HelloCloudFoundry
Once the app is created lets just dummy up a index.gsp, I usally delete the default one grails creates and replace it with my own with body text “HelloWorld”. For this example I replaced the content of the index.gsp with simple html as follows
<html> <head> <title>Hello Cloud Foundry</title> </head> <body> Hello From the Cloud! </body> </html>
Installing cloud foundry plugin
I was pretty impressed that grails already had a cloupowershellpowershelld foundry plugin, to install lets just run our typical grails install as follows
/home/manijshrestha/workspace/HelloCloudFoundry$ grails install-plugin cloud-foundry
Now, it should install the plugin for cloudfoundry
Configuring the App
To set up the app its fairly easy, edit the Config.grooy file found in grails-app/conf/Config.groovy
and set up with your credentials. If you don’t have an account get one via http://www.cloudfoundry.com
You should receive an email with user username and password
grails.plugin.cloudfoundry.username = 'firstname.lastname@example.org' grails.plugin.cloudfoundry.password = 's3kr3t' grails.plugin.cloudfoundry.appname = 'YOUR-APP-NAME'
thats it!!! we about 90 percent done!
Now, lets deploy our app!!! Yes we are there now..
Now lets just run a grails command to push the app to the cloud foundry
from the command line run
NOTE: technically, we should configure our database like mysql or mongodb etc, but for our demo we will just push it, the command will asks us to create one and we will do so.
$grails prod cf-push
You will see some input dialogs asking you for the app url? and also since, we didn’t configure a service it will ask you if you would like to bind a mysql service, See my responses below:
Application Deployed URL: 'manijshrestha.cloudfoundry.com'? manijshrestha.cloudfoundry.com Would you like to bind the 'mysql-XXXX' service? ([y], n) y
And BOOM we are done now you can navigate to your application URL
in my case its
Hopefully you enjoyed this, feel free to comment!