Grails Tip: Deploy to the Cloud with AppFog

Post by Matt Nohr

AppFog LogoAppFog (, @appfog) is a relatively new cloud platform that lets you deploy your applications to one of a number of different cloud providers like HP Openstack, Rackspace, and Amazon Web Services. It supports a number of languages and databases,  but I’ll be focusing on Grails.

The real interesting part to me is that there is a free plan you can use to test your applications. The free plan currently includes unlimited number of applications, as long as you only use 2 GB of RAM. There is a 50 GB data transfer limit, and a 1 GB database limit. If the free plan is not quite enough, they have paid plans starting at $100/month.

AppFog and Grails

If you have a Grails application that you want to deploy to AppFog, it can be a little confusing the first time, but once you go through the process once, following these steps, it should be fairly straight-forward.
Set Up the Application in AppFog

  1. Create an account with AppFog
  2. AppFog - Create App Click the Create App button:
  3.  Choose Java Grails:
  4.  Choose an infrastructure (AWS for example):
  5. Pick a subdomain
  6.  Click Create App:

At this point it does some initialization, including creating and starting a default grails application. You could go to your new URL and see a Grails application running.

Upload Your Grails App

  1. Create a war file for your application (grails war)
  2. Navigate to the /target directory where the .war file was built
  3. The first time, you will have to install the “af” ruby gem. In your app console on AppFog there are instructions under “Update Source Code” for different platforms (or more detailed information here)
  4. Login from the console with the command “af login”. You will have to enter your email and password.
  5. Upload your application with the command “af update <project name>”. This will take a minute or two depending on the size of your application (even a basic Grails application is over 20 MB)

AppFog Update

If you have multiple .war files in the /target directory, it appears to just take the first one it finds. You may want to do some clean-up in that directory if the wrong .war is being uploaded.

Adding a Database

You will probably need to configure a database. First you have to add the database (as a service) to your AppFog console. For this example I’ll be using MySQL:

AppFog - Database

  1. Go to your console
  2. Click “Services”
  3. Click “MySQL” button, give it a name, and click “Create”
  4. Then you may have to “bind” this to your application, so click the “Bind” button.

Configuring the Database

With MySQL (and the other databases), AppFog stores all the login information in a system environment variable called “VCAP_SERVICES”. To use that you will have to update your DataSource.groovy file. Here is an example of how I configured a production datasource:

production {
   def envVar = System.env.VCAP_SERVICES
   def credentials = envVar?grails.converters.JSON.parse(envVar)["mysql-5.1"][0]["credentials"]:null

   dataSource {
      pooled = true
      dbCreate = "update"
      driverClassName = "com.mysql.jdbc.Driver"
      url =  credentials?"jdbc:mysql://${credentials.hostname}:${credentials.port}/${}?useUnicode=yes&characterEncoding=UTF-8":""
      username = credentials?credentials.username:""
      password = credentails?credentials.password:""


Getting your application configured the first time does take a little work. Hopefully this guide makes it a little bit easier. The free plan seems like a good platform to use for testing/proof-of-concept type applications.

This entry was posted in Software Development and tagged , , . Bookmark the permalink.

Related Posts:

6 Responses to Grails Tip: Deploy to the Cloud with AppFog

  1. Saurabh says:

    Thank a lot!.. I have been looking exactly for this. I just followed steps described here and my website is now up :-)..thanks

  2. Thando Mafela says:

    Thanks for the post, you forgot to add the driverClass in the production datasource. Other than that good blog post, it was very helpful.

  3. Matt Nohr says:


    You are correct. I updated the post with the driverClassName. In my application I had set that outside of the “production” environment section, which was not very clear in my example. Thank you for letting me know.

  4. Chris Tacy says:

    Love the post! Thanks. One correction… the cheapest paid plan is actually $50 not $100.

  5. Ab says:

    Correction, now the cheapest paid plan is $20

  6. Howdy very nice site!! Guy .. Excellent .. Superb .. I’ll bookmark your site and take the feeds additionally?I’m satisfied to seek out a lot of helpful info here in the put up, we want work out more strategies on this regard, thanks for sharing. . . . . .

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>