No description, website, or topics provided.
Shell Perl Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Sample nginx + uWSGI stack for OpenShift

This is a collection of scripts that allows you to deploy a project running on a nginx+uWSGI stack on OpenShift.

Quick start

In order to use this repository, you'll have to clone it and use it as the main git repository on a DIY OpenShift Cartridge.

First, create your app with rhc:

$ rhc app create myapp diy-0.1

Now, add this repository to the created git repo and pull from it:

$ cd myapp
$ git remote add upstream
$ git pull -s recursive -X theirs upstream master

As a last step before pushing your changes, you'll need to create the application that will be served by the stack. A app/ script is expected. Create it like the following:

$ mkdir app
$ cat > app/ << EOF
def application(env, start_response):
    start_response('200 OK', [('Content-Type', 'text/html')])
    return ['Hello world']

$ git add app
$ git commit -a -m 'sample application'

Now we're ready to push the changes to our OpenShift repository. Go get a coffee, the scripts will build nginx, Python, and uWSGI from source, it might take a while.

$ git push origin master

During the installation process, there will be some messages indicating progress. A small spinner is used to show that connectivity hasn't been lost.

After the installation is done, you can access your application at myapp-<domain>

$ curl myapp-<domain>
Hello world


There is a video of this process on ASCII.IO. Note that, although it is a simple process, building the software on the host machines takes some time. The total running time of the above video is ~25min. Feel free to skip through the make ... parts until I don't upload a better video.

How it works

OpenShift expects DIY client applications to set up a HTTP server on $OPENSHIFT_INTERNAL_IP:$OPENSHIFT_INTERNAL_PORT. We're using nginx as the HTTP server, passing the request to the uWSGI server which then contacts our WSGI application.

OpenShift HTTP server   -->   nginx   -->   uWSGI   --> application

Building software

The .openshift/action_hooks/build script is responsible for building and installing the dependencies we need, namely nginx, Python 2.7, uWSGI, and the user packages listed in app/requirements.txt.