An OpenShift primer
Hang on to your hats and stand by for launch into the Clouds – how to get your first OpenShift based application deployed in minutes!
Intro / Blurb
Are you tired of requesting a new development machine for your application? Are you sick of having to set up a new test environment for your application? Do you just want to focus on developing your application in peace without ‘dorking with the stack’ all of the time? Have no fear, OpenShift is here! This tutorial will help you get started, hands-on, with Red Hat OpenShift PaaS.
Getting started with OpenShift
There is a great amount of hype in the IT world right now about Cloud. There is no shortage of acronyms for the various areas that have been carved out, like Infrastructure as a Servce (IaaS), Platform as a Service (PaaS) and Software as a Service (SaaS).
OpenShift is a PaaS offering from Red Hat that we will introduce here which provides you with a platform to run your applications. For you as an application developer, you want to look at the environment where you put your applications as just a service that is being provided. You don’t want to bother with how that service is constructed as a set of components, how they are configured or where they are running. You just want to make use of this collection of services as offered to deploy, develop, test and run your application. At this basic level, OpenShift provides a platform for your Java, PHP, Ruby, Perl and Python applications.
A little background
First let’s take a quick look at where OpenShift comes from. It started at a company called Makara that was based in Redwood City, Calif., providing solutions to enable organizations to deploy, manage, monitor and scale their applications on both private and public clouds. Red Hat acquired Makara in November of 2010, and in the following year they have merged Red Hat technologies into a new project called OpenShift.  In May of 2012 the OpenShift team announced the launch of their Open Source project called OpenShift Origin thereby making the entire code base available online.  You can even take it for a spin with the live CD they offer.  Even though this merging of technologies is interesting for developers of PHP, Ruby, Perl and Python, for Java developers the best news is that OpenShift has included the next generation Open Source application platform based on JBoss AS 7.  This brings a lightning fast application platform for all your development needs.
It did not stop there, with the addition of featured applications OpenShift was now offering pre-packaged solutions like JBoss Enterprise Application Platform (EAP), Zend Server, and Aerogear Push. 
The OpenShift website states, “OpenShift is a free, cloud-based application platform for Java, Perl, PHP, Python, and Ruby applications. It’s super-simple—your development environment is also your deployment environment: git push, and you’re in the cloud.”  This peaks the interest so let’s give it a try and see if we can raise our web application into the clouds. For this we have our jBPM Migration web application which we will use as a running application example for the rest of this exercise.  First things first, we need to get the OpenShift client tooling installed on our development machine.
Installing the client tools
Getting started with OpenShift is well documented on the website as a quick start.  First you will want to sign up for a Red Hat Cloud (rhcloud) account on OpenShift, which you can access through the front page. Access the Sign Up For Free button as shown in Illustration 1 with a yellow arrow. 
Illustration 1: sign up for free to start using OpenShift.
Once you have signed up on the form as shown in Illustration 1, we move on to the quick start page found under the Get Started link.  This quick start provides us with the four steps you need to get your application online.
- Sign up for an account.
- Open the console and create an application.
- Install Git and start coding.
- Upload your changes to OpenShift.
These are the basics of using OpenShift and do not require you to install any of the command line tools that a developer might be interested in. For a simple evaluation this might be enough, so if this is what you are interested in please follow the provided instructions.
We are going to take you through the more intensive but rewarding installation of the client tooling on your local machine so that you can access all of the OpenShift commands from your favorite shell. This is outlined for Red Hat Enterprise Linux (RHEL), Fedora Linux, generic Linux distributions, Mac and Windows.
Client tools for RHEL and Fedora
For RHEL and Fedora it is a simple package installation after adding the OpenShift YUM repo:
- Download the express repo file openshift.repo at https://openshift.redhat.com/app/repo/openshift.repo.
- Place openshift.repo file in /etc/yum.repos.d/ directory.
$ sudo mv [path-to-download]/openshift.repo /etc/yum.repos.d/
- Install OpenShift client tools.
$ sudo yum install rhc
For generic Linux distributions, Mac and Windows it is a Ruby based gem installation which we will show here based on the Mac quick start instructions. We leave the generic Linux distribution and Windows installation as an exercise for the reader. 
Client tools for Mac
Before we can begin with our Mac installation of the OpenShift client tools, there are a few requirements we need to satisfy first. The official quick start guide points to a Full Xcode Suite or Git for OS X, but we have a preference for being able to manage our installed packages on our Mac.  There is a choice of projects to manage third party Open Source packages on your Mac such as MacPorts, but we prefer the project called Home Brew.  We installed Home Brew and used this to manage our Git installation. 
# Installation of Home Brew straight from the project installation guide. The command below # installs Home Brew into /usr/local so that you don't need 'sudo' when running a 'brew install # [package]' # $ /usr/bin/ruby -e “$(/usr/bin/curl -fsSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)”
Next we can install ‘git’ package as the needed dependency.
# $ brew install git
Once we have this taken care of the required dependencies, we can actually install our OpenShift client tools with a Ruby Gem install command as follows:
# Install OpenShift rhc client tool. # $ sudo gem install rhc Fetching: net-ssh-gateway-1.2.0.gem (100%) Fetching: net-ssh-multi-1.2.0.gem (100%) Fetching: rhc-1.16.9.gem (100%)
If this is your first time installing the RHC tools, please run ‘rhc setup’
Successfully installed net-ssh-gateway-1.2.0 Successfully installed net-ssh-multi-1.2.0 Successfully installed rhc-1.16.9 3 gems installed Installing ri documentation for net-ssh-gateway-1.2.0... Installing ri documentation for net-ssh-multi-1.2.0... Installing ri documentation for rhc-1.16.9... Installing RDoc documentation for net-ssh-gateway-1.2.0... Installing RDoc documentation for net-ssh-multi-1.2.0... Installing RDoc documentation for rhc-1.16.9...
Now we can view the OpenShift client tooling that is now available with command line # completion. We do this by typing ‘rhc’ and then hitting TAB twice which will produce a listing of available client tools for OpenShift.
# $ rhc rhc rhc-chk rhc-create-domain rhc-ctl-domain rhc-domain-info rhc-snapshot rhc-tail-files rhc-app rhc-create-app rhc-ctl-app rhc-domain rhc-port-forward rhc-sshkey rhc-user-info
There is a complete documentation listing of all the various target systems that can be installed at the OpenShift project documentation site. 
We have taken you from the background of what OpenShift is, where it came from, and how to get started by signing up for a new OpenShift account. We then walked through the various target platforms that can be used for installing the OpenShift client tools. Finally we zoomed in on a Mac system and walked through the details of installing the OpenShift client tools. This is all you need to get your Cloud development experience started with OpenShift!
Now hang on to your hats, you are ready to depart for the Clouds and get our first OpenShift based application deployed in minutes!
- OpenShift, https://openshift.redhat.com
- OpenShift Origin Open Source project,
- OpenShift Origin LiveCD, https://openshift.redhat.com/community/blogs/build-an-open-cloud-getting-started-with-openshift-origin-and-openstack
- JBoss AS 7 in the Cloud, http://www.jboss.org/openshift
- OpenShift Featured Applications, https://openshift.redhat.com/app/console/application_types
- jBPM Migration project web application, https://github.com/eschabell/jbpmmigration_upload
- OpenShift Quick Start, https://openshift.redhat.com/app/getting_started
- Sign up for OpenShift, https://openshift.redhat.com/app/account/new
- Getting started with OpenShift, https://openshift.redhat.com/app/getting_started
- Installing OpenShift RHC client tools (Windows), https://www.openshift.com/developers/rhc-client-tools-install
- Full Xcode installation, https://developer.apple.com/xcode/
- Git for OSX, http://code.google.com/p/git-osx-installer/
- Macports project, http://www.macports.org/
- Home Brew project, http://mxcl.github.com/homebrew/
- Home Brew installation guide, https://github.com/mxcl/homebrew/wiki/installation
- Online documentation for getting started with OpenShift, https://docs.redhat.com/docs/en-US/OpenShift/2.0/html-single/Getting_Started_Guide/index.html
This tutorial is an excerpt from Developer.Press’s OpenShift Primer 2 – Get Your Code into the Cloud by Eric D. Schabell. The next chapters will help you get your first application into the Cloud. You can get it at www.amazon.com/dp/B00JEHGC1G
About the author
Eric D. Schabell is the JBoss technology evangelist for Integration and BPM products at Red Hat. He is responsible for various outbound technical aspects of promoting JBoss Enterprise Middleware integration products and services (BRMS/BPM, SOA, and data integration). He has been working within software development since 1998 for many different enterprises.