I had an issue with deploying my Grails project to Cloud Foundry with using cloudfoundry-grails-plugin.
My application was using Tomcat 7 unlike Cloud Foundry, which use Tomcat 6. In other words, to have a Grails application with Tomcat 7 run,
I had to deploy the entire Tomcat 7 directory, but before it should be slightly reconfigured.
Here's a link with a great tutorial on how to get Tomcat 7 up and running on Cloud Foundry.
After doing those tricky steps, I had to configure mysql.
Cloud Foundry doesn't give you information about your available database services. Instead it has an environment variable named VCAP_SERVICES, which
contains all needed information on how to connect to them from your application. I.e. you have to teach your application how to connect to Cloud Foundry services.
I decided to create util class which would gather database configuration for me, and append it to DataSource.groovy, here it goes:
After doing the previous steps, you're done with configuring, but I've also written a script, which packages war file and copies it's content to tomcat/webapps/ROOT directory.
(this is optional, as you can 'war' your project and extract all packaged files to tomcat/webapps/ROOT manually):
1234567891011121314151617181920212223
/** ExtractArtefact.groovy (script)* run: -Dgrails.env=cf extract-artefact**/includeTargets<<grailsScript("_GrailsWar")includeTargets<<grailsScript("_GrailsEvents")target(extract:"Copy war to tomcat directory and deploy to cloudfoundry"){depends(war)defmetadata=grails.util.Metadata.getCurrent()event("StatusUpdate",["Cleaning deployment directory"])ant.delete(dir:"${basedir}/tomcat/webapps/ROOT")event("StatusUpdate",["Extracting artefact to deploy directory"])defsrc="${basedir}/target/${metadata."app.name"}-${metadata."app.version"}.war"defdest="${basedir}/tomcat/webapps/ROOT"ant.unwar(src:src,dest:dest)event("StatusFinal",["Successfully deployed to target directory"])}setDefaultTarget(extract)
My Tomcat settles in base directory of the project, but you can change the destination url to be an absolute path anywhere in your system.
When script is executed (or you had extracted content of war file to ROOT directory), the last and final step is to execute "vmc push" command from tomcat directory.
Hope this would be helpful!
If you're looking for a developer or considering starting a new project,
we are always ready to help!