Monday, 24 May 2010

Grails on Cloud Foundry

Some brief notes on Getting Started with Grails and Cloud Foundry.  I found the Cloud Foundry getting started page to be excellent, but there are a few details beyond the getting started guide that you need to deploy a real application.

Sign up with Cloud Foundry

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

I found it takes about 48 hours for your sign up to be approved.


follow the instructions on getting started with Cloud Foundry.  Remember to save your RSA Private Key you'll need it for SSH access.

http://www.cloudfoundry.com/getting_started.html

Creating WAR
Before creating the war ensure the DataSource.groovy is set up correctly, to make sure you don't reset the database every time you redeploy  set 

dbCreate = "update"

Now create the war:

grails prod clean
grails war

Deploying WAR
I toyed with the SpringSource Tools Suite, great for Grails development but for Grails deployment to Cloud Foundry it is not quite there yet.  I expect this to improve in the near future.  For now I find it easier to use the Grails Cloud Foundry plugin to upload:


grails cloud-foundry-upload


Then login to the Cloud Foundry web app: https://www.cloudfoundry.com/


on the applications tab select deploy for my application

You need to enter a name or the deployment - aoms

Select the database storage type as EBS New Volume and accept the default volume name, set backup interval appropriately

select Launch button

Subsequently when you redeploy the application you will select either:
- a Snapshot as the storage type and select the appropriate snapshot to restore from (this will result in a new EBS volume being created)
- an Existing Volume as the storage type and select the appropriate volume

You need to manage your EBS volumes and snapshots from the AWS Management Console - https://console.aws.amazon.com/ec2/home

Setting up SSH
For SSH access to my EC2 instance I use putty, the following guide is a great help:

http://docs.amazonwebservices.com/AWSEC2/2007-08-29/GettingStartedGuide/putty.html

You'll need the RSA Private Key you generated when setting up Cloud Foundry



4 comments:

  1. Great post Paul!

    So, have you redeployed new versions of you app? I understand that each version will be available in the "applications"? Is this correct or they will replace the latest one? And the EBS volume with mysql works great?

    Thanks again!

    ReplyDelete
  2. I've found that when you upload a war with the same name it replaces the existing app in the applications tab. So if you want to maintain different versions you will need to manage this via your war naming convention. The deployment tab lists all deployments, I tend to delete these once I stop an instance. I've had no problem with the EBS volume so far, but I'm only getting started ...

    ReplyDelete
  3. Yeah, same name replaces the application. In my case all wars have different names since it corresponds to different versions of the app. I always maintain the 3 or 4 latest versions. I really care about :)

    But I'll try to have 2 different versions in apps (mywar-20100501 and mywar-20100502) for example and try to deploy the second one in the place of the first. I know this would work if they had the same name and one replace the other :)

    Let's see! Thanks man, I'm starting on it either, and think we can help each other!

    :)

    ReplyDelete
  4. Great instructions. I've created a new section on the Cloud Foundry website to capture your post and others that we may encounter (https://www.cloudfoundry.com/screencasts.html#tips). Keep them coming!

    ReplyDelete