CloudBees platform: An Introduction
The world of Java development has changed drastically with Maven and Jenkins/Hudson. Maven has changed the way applications are built and dependencies are managed. While Jenkins has become a tool of choice for continuous integration (CI) and continuous delivery (CD). Exploring these topics in detail is not on agenda today, we will take a look at cloud platform where Java/JVM based developer would be very happy to find all he needs: Welcome to CloudBees. CloudBees provides you services from storing your code in cloud to building and deploying the code in cloud. Without changing the way you work, you can get your application up and running as soon as it is ready! Without further ado, let’s do some hands on!
Prerequisites and Scope
In this tutorial, we are going to use Maven and Jenkins for build and continuous integration respectively . Knowledge of these concepts and tools will help you play along with the tutorial well. Learn more on Jenkins here and more on Maven here
For brevity of this tutorial, we will deploy our application directly to cloud and skip the local deployment part. Also to keep the application simple, we will not configure a database with application and use only in-memory database.
Setup CloudBees and Code Repository
Create CloudBees Account and setup code repository, go to Services –> Repositories and “Create a new code repository”. I chose Git and named it CloudBeesClinic, but you can choose SVN too as your code repository. For purpose of this tutorial I am going to stick with Git.
You will also need a git client before we can push code to our repository. I use GitHub command line client. Once you have setup the git client, generate SSH keys for communication with the code repository. If you are on windows, use git client you just installed and for Linux/Unix based systems directly run following command:
Once keys are generated, copy the public key from id_rsa.pub (That’s default file, if you chose defaults while generating the SSK key) and go to CloudBees Account –> SSH Keys. Add the public key from your machine to CloudBees. For more information on how to install Git client check here and to generate SSH keys check here
Bootstrap the project
We will create a project using a RAD tool: Spring Roo and you can get more details on project creation in this article‘s first section. You should see src directory and other files like pom.xml. Let’s go ahead and push this code to our git repository on CloudBees.
git init // Initializing the Git repo locally git remote add origin ssh://firstname.lastname@example.org/<strong><em>YOUR_CLOUDBEES_ID</em></strong>/CloudBeesClinic.git //(Abve URL is “Authenticated access” field when you created repository in cloudbees) git add -A // Adding all files and subdirectories to repository. git commit -m 'Initial checkin' // Committing to local repository. git push origin master // Pushing the committed changes to server repository.
Setting up project build and deployment
CloudBees provides Jenkins as a tool for continuous integration and delivery. While Jenkins is a very versatile tool and I can write a book over it, let’s start using it in context of our project to better understand it. Go to your cloudbees account –> Services –> Jenkins and create a “New Job” and choose “Build a maven2/3 project” and a suitable job name. I am going to leave most of fields to default for now, and only configure what is needed. So here is our first bare minimum job, which will need following parameters
Deploy now defaults – Checked: This will deploy our build as soon as it is successfully built. Source Code management: Provide the URL to the source code repository, in our case Git. This is same URL we provided earlier while committing the code.
In Build triggers section, I am going to choose “Build periodically” and provide value “00 0-23 * * *” which is a syntax similar to one used in cron jobs. What it is going to do is fire a build 0th minute of every hour. In Post build actions select “Deploy to CloudBees” and provide an appropriate application ID and account you are using.
After you have saved the project/job (Project as Jenkins calls it), do a “Build now” from left menu. Let’s see if our code gets built and can be deployed right away. While project is getting built, you will see a blinking blue signal on the job, and logs can be seen through “Console output”:
Since we have chosen one click deploy, application will be deployed as seen at end of log:
[cloudbees-deployer] 16 MB
[cloudbees-deployer] 17 MB
[cloudbees-deployer] Deployed to application id vishal-biyani/vishalbiyani-cbtest
[cloudbees-deployer] Can be accessed at http://vishalbiyani-cbtest.vishal-biyani.cloudbees.net
[cloudbees-deployer] Recorded deployment in fingerprint record
Hurray!! Application is live: a pet clinic to manage pets and doctors and appointments. It’s a tiny little application, but is good enough for testing basic stuff. Since the build is setup to run every hour, the trend of builds can be seen later. For example in below image, build #23 failed, but other builds have been healthy!
What we have covered in this tutorial is fairly simple, but we got an idea of how simple it is to deploy a Maven based Java project on CloudBees platform. What we have not covered of CloudBees platform is much more, following is a quick roundup of course not exhaustive:
- Code quality tools like Sonar and other plugins for code coverage, test coverage can be installed within Jenkins, like any other Jenkins installation
- Add relational databases like MySQL or non relational databases like MondoDB or CouchDB
- Performance monitoring tools like NewRelic, Email Service like SendGrid etc and many more
Further reading on CI and CD
Continuous integration and delivery is a big topic, and a major differentiator between a good and not so good software project is how well CI and CD practices are set and followed. No discussion on CI and CD on this earth will be complete without following three IMHO:
- Article by Martin Fowler on Continuous integration is a crash course for any beginner: http://martinfowler.com/articles/continuousIntegration.html
- Book on Continuous integration by Paul M. Duvall, Steve Matyas and Andrew Glover
- Book on continuous delivery by Jez Humble and David Farley.
My name is Vishal Biyani! I am an avid developer and a cloud enthusiast! I am lucky enough to witness some very exciting changes in technology and data landscape.