Finally, Redhat has managed to jump the bandwagon and provide a PaaS platform that promises much, Openshift. OpenShift provides PaaS in three flavours, OpenShift Express, OpenShift Flex and OpenShift Power. Each othen read like this.
Free and easy cloud deployments
PHP, Python, Ruby
Git push and leave the rest to us
Auto-scale new and existing apps in the cloud
PHP, Java EE, MySQL, MongoDB, Memcache, DFS
Full control over configuration & Built-in monitoring
Complete control over cloud deployments
Custom topologies, root access, multi-tier dependencies
Turn any application into a cloud deployment template
* Coming soon.
I decided to give OpenShift Express a try as it was free and it supported Python’s WSGI 3.2.1. I decided to take a Bottle wsgi app and put it there. But before I go into how I did this let me share somethings you got know about Openshit Express, just a tiny bit.
OpenShift Express says that you “Start Managing your cloud applications* for free”, but at the moment they allow you create only on application and they have DB size limit of 128MB, but you could still use another External DB.
OpenShift Express says “Deploy your applications to the cloud at no extra cost”, well this is true but they do not mention where your applications are hosted, but they give neat mechanism of git push to puch your app to the their.
OpenShit Express says “Access your containers, such as the file IO, in the cloud”, will agree with this, they do give you a provision to create files and, read and write those files. Not sure if I have seen any restrictions there.
OpenShift Express says “Easily migrate components across OpenShift offerings using its consistent framework across subscription levels”, not sure if I have really seen anything that talks about it.
Thats all, you just need to take care that OpenShift Express does provide any management UI, but their command line client is pretty sufficient and easy to use. They have made sure you dont need learn a plethora of commands to get started, they just have five commands. All you need is Ruby to get going. Windows users need cygwin to be installed.
Lets get started by deploying small expample app, I call “t”. As I have mentioned before t is bottle based wsgi app and require bottle to be installed. But before that lets go over the steps to get to place of actually deploying the app.
First and foremost you need an OpenShift Express account. Create one and make sure you remember your password, this will be needed in every command that you use.
Second, you need install the command line client tools which is pretty straight forward if you have installed Ruby already.
# gem install --source http://gems.rubyforge.org --source http://openshift.redhat.com/app/repo rhc
Now its time get started, for which we need to create a domain name. A domain name is a requirement for each new application that you create in the cloud and is part of the application name and its unique across the their Cloud. I have chose “datapipet” as my domain name.
NOTE: This is not your app name. It will be hyphen append to your app name.
$ rhc-create-domain -n datapipet -l email@example.com Password: Generating Openshift Express ssh key to /home/sam/.ssh/libra_id_rsa Generating public/private rsa key pair. Created directory '/home/sam/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/sam/.ssh/libra_id_rsa. Your public key has been saved in /home/sam/.ssh/libra_id_rsa.pub. . . Contacting https://openshift.redhat.com Adding rhlogin to /home/sam/.openshift/express.conf Creation successful You may now create an application. Please make note of your local config file in /home/sam/.openshift/express.conf which has been created and populated for you.
Now its time to create the app. As mentioned earlier I have chosen “t” to be the name of my app, and its a WSGI application. So the command will look like this.
$ rhc-create-app -a t -t wsgi-3.2.1 Password: Creating remote application space: t Contacting https://openshift.redhat.com RESULT: Successfully created application: t Adding rhcloud.com to ~/.ssh/config Warning: Permanently added 't-datapipet.rhcloud.com,184.108.40.206' (RSA) to the list of known hosts. Receiving objects: 100% (19/19), done. Confirming application racer is available Attempt # 1 Success! Your application is now published here: http://t-datapipet.rhcloud.com/ The remote repository is located here: ssh://firstname.lastname@example.org/~/git/t.git/
Note that now I have URL http://t-datapipet.rhcloud.com/, which I see has page already that tells me what to do next. This is pretty cool and simple right? It also creates local git repository creating a directory “t” where I ran my command from.
In the “t” directory containts three folders “data”, “libs” and “wsgi”. The README has the following description.
wsgi/ – Externally exposed wsgi code goes
libs/ – Additional libraries
data/ – For not-externally exposed wsgi code
Please leave wsgi, libs and data directories but feel free to create additional directories if needed.
Note: Every time you push, everything in your remote repo dir gets recreated please store long term items (like an sqlite database) in ../data which will persist between pushes of your repo.
So what this means is that, the wsgi application that I am about to develop is going to into the wsgi app. But all the support python packages need go into data.
I am creating python virtual environment, using virtualenv, for bottle in my data directory as OpenShift expression only support Django out of the box. This will also give me more control over the my environment and its versions. The following steps allow me to creat the environment.
$ cd data $ virtualenv -p /usr/bin/python2.6 --no-site-packages --distribute env $ source env/bin/activate
Then I install the bottle on top of this virtual environment.
$ easy_install -UZ bottle
Now its time to write the application. I just need to traverse to the wsgi directory and edit the file “application”. The “application” is the default entry script to your wsgi application. It already has a sample script I need to delete it and then write my bottle application.
$ cd ../wsgi $ echo ""> application $ cat > application <<EOF import os here = os.path.dirname(os.path.abspath(__file__)) os.environ['PYTHON_EGG_CACHE'] = os.path.join(here, '..', 'data', 'python-eggs') virtualenv = os.path.join(here, '..', 'data/env/bin/activate_this.py') execfile(virtualenv, dict(__file__=virtualenv)) from bottle import route, default_app @route('/:name') def nameindex(name='World'): return '<strong>Hello %s!</strong>' % name @route('/') def index(): return '<strong>Hello World!</strong>' application = default_app() if __name__ == '__main__': from wsgiref.simple_server import make_server httpd = make_server('localhost', 8051, application) # Wait for a single request, serve it and quit. httpd.handle_request() EOF
I have no need to write the application entry point but then this is useful for me to run the application locally and test it. One to note is that every wsgi application on OpenShift Express will need to have a function named “application”, which is the wsgi handler.
Once I have tested my application, it time to commit and push the app to OpenShift and start it. The following commands will help me do just that. But before I proceed I should just make sure that I do not push any .pyc files.
$ cd .. $ echo '*.pyc' > .gitingnore $ git add . $ git commit -m 'my first commit' $ git push $ rhc-ctl-app -a t -c restart Password: Contacting https://openshift.redhat.com Contacting https://openshift.redhat.com RESULT: Success $
Now I am good to go. I just open up a browser and proceed to my unique url http://t-datapipet.rhcloud.com/. That is it, all you need to do is just make changes, push and restart.
They have definitely taken a leaf out of the Heroku, but they have done well to give support for python and php apart from ruby. But one thing I feel they need take out of heroku is the documentation where heroku is really great in explaining their architectural components, i am sure this will happen, but the question is when. Nevertheless it is heartening to see another PaaS with promise in the horizon.
Good going Redhat!