Nuts & Bolts Admin Story Lead image: © Jasmin Merdan, 123RF.com
© Jasmin Merdan, 123RF.com
 

An IT nomad's diary

At the Press of a Button

Red Hat's new OpenShift PaaS service takes an uncomplicated approach to sending web applications to the cloud. By Thorsten Scherf

Friday, 5pm: I just switched off my laptop a quarter of an hour ago and I am ready to go running, when my phone rings. Two friends from California are calling to proudly tell me about a new Perl web application they are writing. They would like to post the application for a public trial this weekend, but they don't have any free web space and ask if I can help them out.

This is a good opportunity to take OpenShift one step closer to the west coast of the United States, I think, and I forget about running to explain what OpenShift is all about.

OpenShift is a platform-as-a-service (PaaS) cloud service from Red Hat that supports various programming languages, frameworks, and databases. Access is organized by means of various levels. The entry level is known as Express and is freely accessible to any user. A command-line tool gives you the option of offering your own applications in a cloud environment. The supported programming languages in the Express variant are Ruby, PHP, and Perl. The back end is MySQL or SQLite. 128MB disk space and 256MB RAM are the available hardware resources in a shared-hosting environment.

If you need more, you have to upgrade to the Flex level, which means having an Amazon web service account. This level gives the user far more control over the environment, shell access, and the ability to serve up Java applications on a JBoss or Tomcat application server.

The highest level, Premium, is not currently available, but will be shortly. This level provides access to the cloud service provider's complete program. For example, you can serve up standalone programs without a web front end. It also offers a templating system to help scale virtual systems, and more programming languages are supported.

The Express level should be fine for my California colleagues and their Perl application, so I explain the steps necessary to get them started.

To begin, users need to register with the OpenShift website [1]. To install the client tools, you need to configure an additional software repository on your computer. Listing 1 shows you the Yum repository file for Fedora 14/15, or RHEL 6; the OpenShift website has installation how-tos for other systems (including Windows and Mac OS X). Then, store the configuration file for Yum in /etc/yum.repos.d/, for example, as openshift.repo.

Listing 1: Yum Configuration for OpenShift

01 [openshift-express]
02 name=Openshift-express
03 baseurl=https://openshift.redhat.com/app/repo/rpms/$releasever/$basearch/
04 failovermethod=priority
05 skip_if_unavailable=1
06 gpgkey=https://openshift.redhat.com/app/repo/RPM-GPG-KEY-redhat-beta
07 ggpkey=https://openshift.redhat.com/app/repo/RPM-GPG-KEY-redhat-release
08 enabled=1
09 gpgcheck=1

Next, yum install rhc downloads the client tools to the local machine. Before you can really start, however, you'll need to generate a domain name as the initial configuration step.

This name becomes part of your application URL and is unique within the OpenShift environment. Thus, it is a good idea to choose an intuitive name. Listing 2 shows an example.

Listing 2: Your Own Domain in OpenShift

01 # rhc-create-domain -n tuxgeek -l tscherf@gmail.com
02 Password:
03 Generating Openshift Express ssh key to /home/tscherf/.ssh/libra_id_rsa
04 Generating public/private rsa key pair.
05 Created directory '/home/UserName/.ssh'.
06 Enter passphrase (empty for no passphrase):
07 Enter same passphrase again:
08 Your identification has been saved in /home/UserName/.ssh/libra_id_rsa.
09 Your public key has been saved in /home/UserName/.ssh/libra_id_rsa.pub.
10 Creation successful
11
12 You may now create an application. Please make note of
13 your local config file in /home/tscherf/.openshift/
14 express.conf which has been created and populated for
15 you.

The cloud service still needs to know your application's name and the language it is written in. Besides the language itself, you need to specify the version. The idea is that the platform will at some stage support multiple versions of the same language, so it needs to know which version your application uses. An ugly situation could arise, for example, if the server used Python 2 but the program was written in Python 3. A single command is all it takes to create your own application, just like for the domain (Listing 3).

Listing 3: Creating the Application

01 # rhc-create-app -a spaceuploader -t perl-5.10 -l tscherf@gmail.com
02 Password:
03
04 Found a bug? Post to the forum and we'll get right on it.
05     IRC: #openshift on freenode
06     Forums: https://www.redhat.com/openshift/forums
07
08 Attempting to create remote application space: spaceuploader
09 Contacting https://openshift.redhat.com
10
11 RESULT:
12 Successfully created application: spaceuploader
13
14 Checking ~/.ssh/config
15 Contacting https://openshift.redhat.com
16     Adding rhcloud.com to ~/.ssh/config
17 Now your new domain name is being populated worldwide (this might take a minute)...
18 Pulling new repo down
19 Warning: Permanently added 'spaceuploader-tuxgeek.rhcloud.com,174.129.129.190' (RSA) to the list of known hosts.
20 Enter passphrase for key '/home/tscherf/.ssh/libra_id_rsa':
21 Confirming application spaceuploader is available
22   Attempt # 1
23
24 Success!  Your application is now published here:
25
26       http://spaceuploader-tuxgeek.rhcloud.com/
27
28 The remote repository is located here:
29     ssh://df488b98f21847c6907a6b2193bff2dc@spaceuploader-tuxgeek.rhcloud.com/~/git/spaceuploader.git/
30
31 To make changes to your application, commit to spaceuploader/.
32 Then run 'git push' to update your OpenShift Express space

As you can see from Listing 3, you just need to upload your application to the server to complete the process. Because the version control system is Git [2], this process is straightforward, and can be done in a couple of steps. The tool also creates a Git project folder when it creates the application. The folder contains the mandatory directory structure. For example, the spaceuploader/perl subfolder expects the code files.

You can list the Perl modules on which your application depends in the deplist.txt; these modules are automatically installed if you do so. A readme file tells you about the other folders and their tasks. Then, you can issue a git commit -a -m "first commit for world domination" to push the files into the Git repository. The git push origin master command transfers the data from the local to the remote Git repository. The application is now available to the general public via the URL shown previously.

Calling rhc-user-info gives you the details of the application (i.e., the HTTP and Git URLs) and the framework in use, which happens to be Perl 5.10, in this case. If you later want to modify an application that you have created to add a database, for example, or stop the web service, or retire it completely, the rhc-ctl-app tool lets you do that as well.

The process is complete. The application is online; my colleagues are happy and can post new versions of their application in the cloud on the weekend to their hearts' content. I'm confident that they won't need my help to do so. After wishing them much fun, I say goodbye and can finally set off on my run – only 15km today, so I should be back home soon.