Monthly Archives: January 2014

Flask Hello World on OpenShift


Building further on the very simple Hello World Flask app that I created, I wanted to see how difficult it was to do the same on OpenShift. Luckily, the Openshift team has prepared a template app for deploying Flask apps on Openshift. That makes life a bit easier.

$ rhc app create hello python-2.7
Application Options
Domain:     wymedia
Cartridges: python-2.7
Gear Size:  default
Scaling:    no

Creating application 'hello' ... done
Waiting for your DNS name to be available ... done
Cloning into 'hello'...
The authenticity of host ' (' can't be established.
RSA key fingerprint is cf:ee:77:cb:0e:fc:02:d7:72:7e:ae:80:c0:90:88:a7.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ',' (RSA) to the list of known hosts.

Your application 'hello' is now available.

  SSH to:
  Git remote: ssh://
  Cloned to:  /home/cisco/Documents/training/Flask_Todo_SQLAlchemy/hello

To see a bit more information about the app, we can use the show-app command from Openshift.

$ rhc show-app hello
hello @ (uuid: 53fb256e4382ec3a4e0001ad)
  Domain:     wymedia
  Created:    2:00 PM
  Gears:      1 (defaults to small)
  Git URL:    ssh://
  Deployment: auto (on git push)

  python-2.7 (Python 2.7)
    Gears: 1 small

Next, we will add the upstream repository to our local git config and we will pul the sample app to our local app.

$ git remote add upstream -m master git://
$ git pull -s recursive -X theirs upstream master
warning: no common commits
remote: Counting objects: 122, done.
remote: Total 122 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (122/122), 16.29 KiB, done.
Resolving deltas: 100% (53/53), done.
From git://
 * branch            master     -> FETCH_HEAD
Merge made by the 'recursive' strategy.
 .gitignore                          |    4 +++
 .openshift/action_hooks/build       |    5 ++++
 .openshift/action_hooks/deploy      |    5 ++++
 .openshift/action_hooks/post_deploy |    4 +++
 .openshift/action_hooks/pre_build   |    5 ++++
 README                              |   55 +++++++++++++++++++++++++++++++++++                           |   39 +++++++++++++++++++++++++                            |    4 +--
 wsgi/application                    |   22 ++++++++++++++
 wsgi/                  |   10 +++++++
 wsgi/static/README                  |   12 ++++++++
 11 files changed, 163 insertions(+), 2 deletions(-)
 create mode 100644 .gitignore
 create mode 100755 .openshift/action_hooks/build
 create mode 100755 .openshift/action_hooks/deploy
 create mode 100755 .openshift/action_hooks/post_deploy
 create mode 100755 .openshift/action_hooks/pre_build
 create mode 100644 README
 create mode 100644
 create mode 100644 data/.gitkeep
 create mode 100644 libs/.gitkeep
 create mode 100644 wsgi/application
 create mode 100644 wsgi/
 create mode 100644 wsgi/static/README

The folder structure that we will have after pulling the repository will look like:


Next, we will push the local git to our Openshift application.

$ git push
Counting objects: 129, done.
Compressing objects: 100% (64/64), done.
....[output from git]
remote: Starting Python 2.7 cartridge (Apache+mod_wsgi)
remote: Application directory "wsgi/" selected as DocumentRoot
remote: Application "wsgi/application" selected as default WSGI entry point
remote: -------------------------
remote: Git Post-Receive Result: success
remote: Activation status: success
remote: Deployment completed with status: success
To ssh://
   96583b2..409254b  master -> master

We can then go to our Openshift application to see the results. See the screenshot below. We have now our Hello World running on Openshift.


I have added the full code to Github