in grails continuous-integration CI Openshift java Tomcat Codeship ~ read.

Fast continuous integration for developer (Grails + Openshift)

Let's talk a little bit about introducing of continuous integration (CI) to a fresh project. Of course, I will talk about small projects where a developer has to find a solution of infrastructure problems by himself and in best case solution should be free. At big projects, you can find a special person or even division that are working with infrastructure issues, so it is not so interesting. One more note: I will talk about CI solution for Grails project, but it can be very easily adapt to any language or framework.

Ok, my project using BitButcket as VCS. What I need next is a build platform. I took Codeship. It is free (until you want parallel build). And the last thing is hosting. In my case, I was looking for java hosting to be able to run grails application. I started with Heroku, but soon I realized that there are very strict limits on database size, so I switched to Openshift and it suits me for pet projects. It also (as Heroku) gives you a free account with 3 engines for you applications + you can use 1Gb free MySQL DB.

Let's start with Codeship. Link it to your VCS system (My Account->Connected Services) and create a new project (choose a repository, branch to build).

Create a new project at Openshift. In the case of Grails, I have chosen Tomcat 7(JBoss EWS 2.0) cartridge. In settings of Openshift account add new SSH-RSA key, fill its content with Codeship ssh key (Project Settings->General->SSH public key). Now Codeship could connect to Openshift for deploying of artefacts.

Now test, build and deploy phases should be configured at Codeship. I was using Gradle as build tool with Gradle Wrapper, so my test and deploy phase script (Project Settings->Test):

./gradlew test
./gradlew assemble

In the case of Maven just use mvn <step name>.

Deployment to Openshift was a little bit tricky. Every Openshift has it's own git repository, where you commit code or artefacts and Openshift hooks will do all the rest job for you (build, put artefacts in a correct directory and restart container). I want to avoid rebuilding, also, there are problems with building of application directly on Openshift box due to limits with RAM (if we are talking about free account). I try to commit WAR-file that was produced by Codeship directly in git repository of Openshift. It worked... for 4-5 builds. Then during checkout of git repository Openshift engine had no enough memory to pack git repository with some huge WARs (about 100 Mb each).

The new solution is to make deploy as simple as it could be: use scp command to copy new war directly in webapps Tomcat directory on Openshift. And it works perfectly. Copy ssh user and host for git repository on Openshift (on a page of Openshift project you can find the full path which looks like ssh://<some_hash>, but you need only <some_hash> Using it Codeship script (Project Settings->Deployment) to deploy WAR file in case of Grails:

scp -rp /home/rof/src/<codeship_account>/<codeship_project>/webapps/ROOT.war <some_hash>

Now every time I make a commit to VCS, Codeship prepare WAR file and deploy it to Openshift. Two minutes later I can see a new version of a web application running.