Deploy application on OpenShift

Posted by 4Aiur on 04/03/2012 in Python |

Deploy application on OpenShift

Prepare environment

Install OpenShift client command line tool

gem install rhc

Generate a new SSH key

ssh-keygen -t rsa -f ~/.ssh/rhcloud -C ""

edit ~/.ssh/config

Host *
    IdentityFile ~/.ssh/rhcloud

Create a Namespace

rhc-create-domain -n namespace -a ~/.ssh/rhcloud -l rhlogin

Create a application, and clone the git reposity

rhc-create-app -a webpy -t python-2.6 -l rhlogin

Write your application



edit wsgi/application

import os

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:

import web

urls = (
        '/', 'index',
        '/hello/(.*)', 'hello'

class index:
    def GET(self):
        return 'Welcome to my web site!'

class hello:
    def GET(self, name):
        if not name:
            name = 'World'
        return 'Hello, ' + name + '!'

application = web.application(urls, globals()).wsgifunc()

# Below for testing only
if __name__ == '__main__':
    from wsgiref.simple_server import make_server
    httpd = make_server('localhost', 8080, application)
    # Wait for a single request, serve it and quit.
    # app = web.application(urls, globals())

Commit and push your code

git status
git add wsgi/application
git commit -m "first commit"
git push

Bind your Domain

rhc-ctl-app -a webpy -l rhlogin -c add-alias --alias yourdomain

Using browser access your web site, Enjoy!

Tags: ,

Copyright © 2010-2024 4Aiur All rights reserved.
This site is using the Desk Mess Mirrored theme, v2.5, from