Friday, March 23, 2012

The Cloudbees cloud solution

A few weeks ago, I blogged about getting your app online with Google App Engine. While this is a very easy process, it is far from the only cloud solution available. I have tried another one, Cloudbees, and will tell you about my experience now.

Cloudbees offers more then just a deployment platform. It has Repositories, Continuous Itegration and an Application Server for you to play around with. It also offers database services, and has plugins for numerous other things (like Sonar, Sauce Labs and many others). For this next example, I used SVN as repository, Jenkins as CI and Tomcat as app server.

Signing up

Signing up for Cloudbees is easy. Fill in your name and e-mailaddress, and create an account. That's it! Now that your account has been created, you can select which services to use. There are both free and paying options. To get started, I added the following:
  • Repository
  • Jenkins
  • Applications
I chose the free version of each. The idea was to simulate a real world working environment. I know there are a SDK and plugins available to build and deploy from within Eclipse/STS, but I wanted to have a continuous integration build my SVN repository whenever I checked in changes.

Configuration

First, I created a new code repository (in the Repositories service). I named it 'blogtryouts'.

Then I created a new application, naming it, again, Blogtryouts.


You now can configure the application server, which is in fact a Tomcat instance. You can define JDBC-connections, or upload a WAR file to be deployed.

Continuous integration

But we don't just want to upload a WAR file. We want our newly created SVN repository to be checked out, the project to be built and the resulting WAR-file to be automatically deployed. Therefore, we'll create a Jenkins service in Cloudbees. I created a DEV@Cloud free instance.

The Jenkins instance is immediately available. I added a new job ('Blogtryouts', who'd have guessed?), and made it a Maven 2/3 project. Once created, we can start configuring our Jenkins build!

Checkout, build, deploy

The configuration is pretty easy as well. The first thing we want Jenkins to do, is checkout our SVN repository. Under Manage sourcecode, you can select Subversion and then specify a URL. That URL is the one Cloudbees gave you when you created your repository. You can find it by going to Services -> Repositories and selecting your repository.

Since we told Jenkins it's a Maven project, it'll automatically try to build the pom.xml. You can add parameters and specify when it should be built. Under Building Activators check Build when a change is pushed to CloudBees Forge. This will start a build when someone commits code to SVN.

Last but not least ,we want to deploy the built artifact. Therefore, check Deploy to CloudBees under Actions after build. You can now specify the site and application ID to deploy to. The site is normally your username, application ID is the name you gave your application, prefixed with yoursite/. Cloudbees helps a lot by providing a dropdown with sites, and by telling you an application ID can't be found. They can even tell you which application IDs are valid.

If you now click 'build now', There will be a warning that your account hasn't been validated. This is an extra step required. Just click the link and enter your phone number (make sure you're near the phone with that number!). Seconds later, you'll receive a phone call with a computer voice telling you a PIN code. Enter the pin code, and you're good to go.

The webapp

So, now that our cloud is fully setup, we of course need a webapp to deploy. For demonstration purposes, we'll just use a general Maven archetype. As in some of my prvious blogposts, we'll create a Wicket project. We can do this quickly by executing this Maven command:

mvn archetype:generate -DarchetypeGroupId=org.apache.wicket -DarchetypeArtifactId=wicket-archetype-quickstart -DarchetypeVersion=1.5.5 -DgroupId=com.mycompany -DartifactId=myproject -DarchetypeRepository=https://repository.apache.org/ -DinteractiveMode=false

The magic

Now that our application has been created, we just have to import it into our SVN repository. I used TortoiseSVN to do an Import to my Cloudbees repository. It doesn't matter how you do it, but once the import's been done, you can watch the magic happen.

Jenkins will notice a new commit and will start a new build. When that's done, it'll deploy the generated WAR-file. When you now go to Services -> Applications, and click your application, you'll notice a new deploy has been done, with a Jenkins build message. This means your app is up and running! The URL is found on top of this page as well. Mine is available here.

No comments:

Post a Comment