Saturday, September 28, 2013

Open Shift Django Basic

My 1 week research on various Paas ended at open shift.
I was a fan of heroku. Some pros of  openshift are 3 gears instead of 1 single dyno
and each gear have a 512MB memory, 1GB local storage than read only file system.
So a total of 1.5GB Ram and 3GB storage :)

Now coming to django to openshift

install rhc using

sudo gem install rhc

create an open shift app using

rhc app create APPNAME python-2.7 -s

-s is for auto scaling



uncomment the line install_requires=['Django==xxxxxxx
and change it according to the required django version if its 1.5.1


save and exit

git commit -am 'Initial commit'
git push

django app should be put in side wsgi

cd wsgi startproject PROJECTNAME

edit the file application

nano application

delete the contents and paste the new contents

import os, sys

sys.path.append(os.path.join(os.environ['OPENSHIFT_REPO_DIR'], 'wsgi',

virtenv = os.environ['APPDIR'] + '/virtenv/'
os.environ['PYTHON_EGG_CACHE'] = os.path.join(virtenv, 'lib/python2.6/site-packages')
virtualenv = os.path.join(virtenv, 'bin/')

    execfile(virtualenv, dict(__file__=virtualenv))
except IOError:

# IMPORTANT: Put any additional includes below this line.  If placed above this
# line, it's possible required libraries won't be in your searchable path
from django.core.handlers import wsgi
application = wsgi.WSGIHandler() 

Now push the changes

cd ..
git add .
git commit -a -m "Project Creation"
git push 

Wait for push to finish,

One drawback of openshift is the time take to restart an app after a change is pushed.

1 comment:

  1. will this work if you are using virtualenv/virtualenvwrapper ?
    and is it possible to push to openshift and git at the same time?