Giter Site home page Giter Site logo

peterfroehlich / openshift-advanced-python-cartridge Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gsterjov/openshift-advanced-python-cartridge

0.0 1.0 0.0 2.34 MB

An OpenShift cartridge which adds support for various python web servers

License: Other

Shell 25.32% Python 74.68%

openshift-advanced-python-cartridge's Introduction

OpenShift Advanced Python Cartridge

Inspired by the Advanced Ruby Cartridge this cartridge attempts to add support for the various WSGI-compliant python servers to the OpenShift platform. It does this by combining a modified python cartridge with the downloadable Nginx cartridge as a reverse proxy.

Why?

The official python cartridge uses Apache and mod_wsgi to serve your app which isn't asynchronous and presents a problem for websockets. An alternative is to provide an app.py file which allows you to avoid mod_wsgi and use something like gevent, but that elimintates the ability to serve static files through a fast webserver like Apache or Nginx.

Installation

To install this cartridge use the cartridge reflector when creating an app

rhc create-app myapp http://cartreflect-claytondev.rhcloud.com/reflect?github=gsterjov/openshift-advanced-python-cartridge

Usage

Using the cartridge isn't very different to the official python cartridge. Instead of providing a WSGI application() function at wsgi/application you instead provide the application() function at app.py. This file will be used directly by all the available servers.

By default wsgiref is used so a working environment can be provided immediately. This is easily changed by setting the OPENSHIFT_PYTHON_SERVER environment variable and then restarting or redeploying the app.

rhc env set OPENSHIFT_PYTHON_SERVER=gunicorn
rhc app restart

Be aware, however, that restarting/redeploying after changing servers for the first time might take a fair amount of time. This is because the server packages get compiled and installed on an as needed basis. Gevent and Gunicorn (which is configured to use gevent as its workers), for example, needs to be compiled within the app as OpenShift doesn't provide it as a system level package.

Supported servers

  • wsgiref
  • gevent
  • gunicorn

Configuration

There is little to no configuration required as most of the details lay in the interaction between Nginx and the WSGI server package. All that is required is to define the application() function in app.py. Any configuration for the server package will be exposed via environment variables.

Environment Variables

OPENSHIFT_PYTHON_WORKERS - The number of workers to spawn for packages like gunicorn. Default: number of CPUs * 2 + 1

Static files

Static files will be served from the public/ directory. These files will be served directly by Nginx.

Web Sockets

Web socket support is enabled in Nginx, however it does little more than passing the requests through with the appropriate upgrade headers. More complex websocket environments will need to go for the customised nginx.conf option.

In the future there might be a nicer way to support websockets as a completely separate server. For example, the application might be served out by gunicorn, but websocket services served out with twisted or tornado. These are purely thoughts at the moment however.

Custom nginx.conf

Like the standalone Nginx cartridge, its possible to provide your own server configuration to be included in the main nginx.conf file. A sample is provided in the cloned repo as nginx.conf.erb.sample. Simply remove the .sample suffix and commit the changes.nginx.conf.erb will be processed and included in the main configuration every time the server starts.

openshift-advanced-python-cartridge's People

Contributors

gsterjov avatar peterfroehlich avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.