Deploy web.py application on OpenShift

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

Deploy web.py 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 "your_email@youremail.com"

edit ~/.ssh/config

Host *.rhcloud.com
    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 setup.py

install_requires=['web.py>=0.36'],

edit wsgi/application

#!/usr/bin/python
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/activate_this.py')
try:
    execfile(virtualenv, dict(__file__=virtualenv))
except IOError:
    pass

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.
    httpd.handle_request()
    # app = web.application(urls, globals())
    # app.run()

Commit and push your code

git status
git add setup.py 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 BuyNowShop.com.