Search code examples
mongodbgrailscloud-foundryappfoggrails-2.1

How to deploy Grails with MongoDB on AppFog/CloudFoundry?


Grails works great with the mongodb plugin locally but I'm having issues on AppFog.

The instructions for deploying Grails on AppFog are fairly clear for databases other than MongoDB. The documentation seem to allude to auto-config for MongoDB but if I have my configuration set to the following, it doesn't work.

//DataSource.groovy

grails {
  mongo {
    host = "localhost"
    port = 27017
    databaseName = "dbname"
  }
}

Auto-config doesn't seem to replace localhost with the proper hostname. It seems like I need to set the values from the VCAP_SERVICES.


Solution

  • Do you have the CloudFoundry plugin installed in your Grails project? The plugin does the auto-reconfig for the MongoDB and other data sources in a Grails app.

    If for some reason you can't, or don't want to, use the Grails CloudFoundry plugin, another alternative to using the environment variables as you showed above is to use the cloudfoundry-runtime Java API. This API gives you access to the same info as is stored in the environment variables, but it is a little cleaner than parsing the environment variables directly.