Grails is a great choice for writing a webapp and focusing on the domain solutions as you get so much out of the box. One gripe I have with it is the speed of building wars, it seems very slow for what is does, but I probably don’t understand the complexity of whats involved, and I don’t want to know, that’s why I chose Grails 🙂
If you are doing regular deploys with Grails, you will soon tire of building using the command line or an IDE like Eclipse or NetBeans (I favor NetBeans for Grails development, feels more lightweight than the STS eclipse version). To solve this, lets bring in Jenkins, a great tool which allows you to automatically build and deploy software, it does a lot more than that, but this is what I want from it.
My App Server of choice is Tomcat 7.x, lightweight, simple to configure, nice! For good measure, I also have MySQL 5.x installed, it’s good to have a database around for all sorts of reasons.
Firstly perform default installs of Tomcat and MySQL (I recommend XAMPP as an easy way of getting Tomcat + MySQL setup). Once that is complete, we now need to configure some users in TC, I want 2 separate users, one to login to the really handy ‘manager’ app that comes with TC, the other to allow scripted access to control TC, this is what Jenkins will use to deploy the war later.
Open tomcat/conf/tomcat-users.xml in your editor of choice, and modify it to look something like this:
<tomcat-users>
<role rolename="admin"/>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<user username="admin" password="password"
roles="standard,manager,admin,manager-gui"/>
<user username="jenkins" password="jenkins"
roles="manager-script"/>
</tomcat-users>
This is creating the two roles manager-gui (for tomcat:port/manager access) and manager-script (for jenkins to deploy war’s through) Once that is complete, restart tomcat for it to take effect.
Installing Jenkins
Installing Jenkins is relatively simple, you download the war from Jenkins home page and either deploy it via the TC manager or drop it into the webapps folder inside TC install directory. Once deployed, browse to http://tchost:tcport/jenkins and you will see the Jenkins screen.
Jenkins is extensible via plugins, and we will need a few plugins to allow us to talk to tomcat, mercurial and grails. Go to the Jenkins plugins menu via “Manage Jenkins” and install the following plugins:
– Jenkins Mercurial plugin
– Jenkins Grails plugin
– Deploy to container Plugin
Once these are installed, configure the deploy plugin to point at the Tomcat ip and use the username and password as above (jenkins/jenkins), the plugin can now auto-deploy to Tomcat.
Next create a job in Jenkins that uses Mercurial as source control, you can pick any branch/Tag etc, but just leave it as default for now. Choose how often to checkout and build, choose which artefacts to archive (at a minimum you should choose the .war in target directory). Then as a post build process, choose to use the auto deploy plugin, this will push the .war file to Tomcat.
Thats it, now you have an auto-building and auto-deploying web application, ENJOY!
