Permalink
Browse files

first rev of Flask for OpenShift Express

  • Loading branch information...
0 parents commit ef39c3ae517c6d37e9a48ab66c0f87dd53fe6121 @dblado dblado committed Sep 28, 2011
Showing with 131 additions and 0 deletions.
  1. +4 −0 .openshift/action_hooks/build
  2. +52 −0 README
  3. +30 −0 README.md
  4. 0 data/.gitkeep
  5. 0 libs/.gitkeep
  6. +10 −0 setup.py
  7. +13 −0 wsgi/application
  8. +10 −0 wsgi/myflaskapp.py
  9. +12 −0 wsgi/static/README
@@ -0,0 +1,4 @@
+#!/bin/bash
+# This is a simple build script, place your post-deploy but pre-start commands
+# in this script. This script gets executed directly, so it could be python,
+# php, ruby, etc.
@@ -0,0 +1,52 @@
+Feel free to change or remove this file, it is informational only.
+
+Repo layout
+===========
+wsgi/ - Externally exposed wsgi code goes
+wsgi/static/ - Public static content gets served here
+libs/ - Additional libraries
+data/ - For not-externally exposed wsgi code
+setup.py - Standard setup.py, specify deps here
+../data - For persistent data (also env var: OPENSHIFT_DATA_DIR)
+.openshift/action_hooks/build - Script that gets run every push, just prior to
+ starting your app
+
+
+Environment Variables
+=====================
+
+OpenShift Express provides several environment variables to reference for ease
+of use. The following list are some common variables but far from exhaustive:
+
+ os.environ['OPENSHIFT_APP_NAME'] - Application name
+ os.environ['OPENSHIFT_APP_DIR'] - Application dir
+ os.environ['OPENSHIFT_DATA_DIR'] - For persistent storage (between pushes)
+ os.environ['OPENSHIFT_TMP_DIR'] - Temp storage (unmodified files deleted after 10 days)
+
+When embedding a database using rhc-ctl-app, you can reference environment
+variables for username, host and password:
+
+ os.environ['OPENSHIFT_DB_HOST'] - DB host
+ os.environ['OPENSHIFT_DB_PORT'] - DB Port
+ os.environ['OPENSHIFT_DB_USERNAME'] - DB Username
+ os.environ['OPENSHIFT_DB_PASSWORD'] - DB Password
+
+To get a full list of environment variables, simply add a line in your
+.openshift/action_hooks/build script that says "export" and push.
+
+
+Notes about layout
+==================
+Please leave wsgi, libs and data directories but feel free to create additional
+directories if needed.
+
+Note: Every time you push, everything in your remote repo dir gets recreated
+please store long term items (like an sqlite database) in ../data which will
+persist between pushes of your repo.
+
+
+Notes about setup.py
+====================
+
+Adding deps to the install_requires will have the openshift server actually
+install those deps at git push time.
@@ -0,0 +1,30 @@
+Flask on OpenShift Express
+============================
+
+This git repository helps you get up and running quickly w/ a Flask installation
+on OpenShift Express.
+
+
+Running on OpenShift
+----------------------------
+
+Create an account at http://openshift.redhat.com/
+
+Create a rack-1.1 application
+
+ rhc-create-app -a flask -t wsgi-3.2
+
+Add this upstream flask repo
+
+ cd flask
+ git remote add upstream -m master git://github.com/openshift/flask-example.git
+ git pull -s recursive -X theirs upstream master
+
+Then push the repo upstream
+
+ git push
+
+That's it, you can now checkout your application at:
+
+ http://flask-$yourdomain.rhcloud.com
+
No changes.
No changes.
@@ -0,0 +1,10 @@
+from setuptools import setup
+
+setup(name='YourAppName',
+ version='1.0',
+ description='OpenShift App',
+ author='Your Name',
+ author_email='example@example.com',
+ url='http://www.python.org/sigs/distutils-sig/',
+ install_requires=['Flask>=0.7.2'],
+ )
@@ -0,0 +1,13 @@
+#!/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
+
+from myflaskapp import app as application
+
@@ -0,0 +1,10 @@
+from flask import Flask
+app = Flask(__name__)
+
+@app.route("/")
+def hello():
+ return "Hello World!"
+
+if __name__ == "__main__":
+ app.run()
+
@@ -0,0 +1,12 @@
+Public, static content goes here. Users can create rewrite rules to link to
+content in the static dir. For example, django commonly uses /media/
+directories for static content. For example in a .htaccess file in a
+wsgi/.htaccess location, developers could put:
+
+RewriteEngine On
+RewriteRule ^application/media/(.+)$ /static/media/$1 [L]
+
+Then copy the media/* content to yourapp/wsgi/static/media/ and it should
+just work.
+
+Note: The ^application/ part of the URI match is required.

0 comments on commit ef39c3a

Please sign in to comment.