Thursday, August 20, 2009

Grails on Cloud Foundry: Step by Step



After being acquired themselves last week, SpringSource has now announced acquiring Cloud Foundry. Currently Cloud Foundry only supports Amazon AWS/EC2 but in the future also VMware vSphere will be supported (surprising isn't it?).

This evening I experimented with Cloud Foundry and have uploaded a simple Grails application to the SpringSource Cloud Foundry Enterprise Java Cloud. I like to share my experiences with this step by step guide.


  1. Sign up for Cloud Foundry at https://www.cloudfoundry.com/cfapp/reg.html?_flowId=register-flow.

  2. Sign up for Amazon AWS at http://www.amazon.com/gp/aws/registration/registration-form.html.

  3. Create an EC2 keypair using the AWS Management Console or ElasticFox FireFox plugin. For detailed info and screenshots check Chris Richardson's blog post about this subject.

  4. Enable SSH using the AWS Management Console or ElasticFox. See Security Groups section. Again, for more info check Chris Richardson's blog post about this subject.

  5. Also enable HTTP access on port 80. If you forget this you won't be able to access your application in the cloud. I searched more than a hour for this...

  6. Change DataSource.groovy:

    environments {
    development {
    dataSource {
    dbCreate = "create-drop" // one of 'create', 'create-drop','update'
    driverClassName = "com.mysql.jdbc.Driver"
    username = "book"
    password = "book"
    url = "jdbc:mysql://${System.getProperty("dbHostName", "localhost")}/book"
    }
    }
    }

    Change the username, password and database name (in url property). You will need to enter these credentials in Cloud Foundry later.
    The "dbHostName" property is specific for Cloud Foundry as explained in Cloud Foundry Getting Started.

  7. Download the MySQL Connector/J jar and add it to your project's lib folder.

  8. After changing DataSource.groovy and adding the MySQL jar build a Grails war file using grails war.

  9. Login to Cloud Foundry at http://www.cloudfoundry.com/. Don't use IE7! Be warned.

  10. Navigate to the applications tab and upload you war file. Important things to enter are the application name, the war file to upload, context name and the database section. Leave the rest as is.

  11. After your application is uploaded it's time to deploy it. Click the application's deploy button. In the next screen just enter a deployment name and leave the rest as is. Now hit the Launch button.

  12. This will take some time, but it's worth it ;-)

  13. After lauching your application click to view the deployment details. There is a Go To Home Page link to access your application!

    Note: If you are using Google Chrome you won't see the link... That's why my first deployment 'failed' (and a hour gone) as I didn't know how to access it. As IE7 doesn't work either I guess Cloud Foundry only supports FireFox currently (I don't mind about IE, but I would be happy with Chrome).



To be honest Cloud Foundry has some rough edges in terms of documentation and tooling support but at the end I'm very happy how simple it is to deploy a Grails application. No Apache, Tomcat or MySQL setup anymore. This is the future!

Now only pricing should be more affordable. $79,20 p/month (Amazon AWS) for a toy project/application is a little bit high.

17 comments:

Dean Del Ponte said...

Thanks for the documentation!

Unknown said...

I agree about the pricing for Amazon's services. Once the additional Cloud Foundry services come out of beta I assume they won't remain free. Seems good for a site that makes money but maybe not pet projects.

Marcel Overdijk said...

@Ed.T: Yes I guess Cloud Foundry services won't remain free. But perhaps with vSphere's prices will be more affordable compared to Amazon.

Hubert Klein Ikkink said...

Great post. Really useful to have a step by step instruction where you've already identified the pitfalls. Saves a lot of time (and frustration).
I agree the price is still high for private / little projects. But to get on the Amazon EC2 cloud wagon seems very easy with Cloud Foundry. And maybe in the future we can deploy to other clouds with Cloud Foundry as well with other pricing.

Unknown said...

Thanks for this. Waiting for my cloud foundry sign-up email now. I too hope vSphere is cheaper than Amazon. Hopefully pricing will be a sweet spot between Google AppEngine (i.e. free) and AWS.

Marcel Overdijk said...

@Chris B: I hope the same! I think many Java developer now build toy/home projects in php just for hosting cheaply. If SpringSource Cloud Founddry can fill the gap they have a lot of potential. But on the other hand they are aiming for enterprises I think...

Unknown said...

I just tried and it seems my application fails to boot because it cannot find MySQL driver. What should I do?

Marcel Overdijk said...

@sarbogast Add the MySQL jar to your project's lib dir. I will add this to the steps. Thanks!

Unknown said...

Thanks a lot, it worked great. Now, I agree with you: 79$ a month is a little expensive. My dedicated server is cheaper.

Dean Del Ponte said...

I agree on the vSphere pricing angle. It would be very compelling if they charged only for cpu utilization.

Unknown said...

If dedicated EC2 pricing is tough to swallow for your pet projects, check out our http://www.stax.net beta which supports pooling your applications across fractions of EC2 servers so you can scale your deployments down to a portion of a single server or up through a multi-server dedicated cluster. There are no EC2 server charges for usage of the shared server zone during the beta.

Roshan Shrestha said...

In the generic installation of EC2 image, the data will be lost if EC2 image is terminated, unless you configure MySQL to save the data in EBS volume.

Same with any changes you make to the app later on. You will need to re-create the image and re-register it every time you make a change.

I hope Cloud foundry makes the above steps unnecessary.

Marcel Overdijk said...

@Roshan Shrestha: Thanks for the info. I think Cloud Foundry will be handling this in the future.

Marcel Overdijk said...

@swashbuck1r: Maybe Cloud Foundry can offer something similar like Stax in the future?

Unknown said...

Make sure your war has no spaces in the filename, else the deploy fails. I (stoopidly) had a space in the app.version in the grails application.properties...

Roshan Shrestha said...

Rightscale already does what Cloudfoundry does and more, except the price is a steep $500/month (http://highscalability.com/hotpads-shows-true-cost-hosting-amazon).

If its only deploying your application to Amazon, it is not really hard at all - I am doing it myself. The value add would be the management, auto-scaling, fail-over, etc.

I hope the offerings from Cloud foundry will be a lot cheaper than Rightscale's offering.

Anonymous said...

It was rather interesting for me to read the blog. Thank author for it. I like such themes and everything that is connected to them. I definitely want to read more on that blog soon.