diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7053ad5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,64 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*.pyc + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.cache +nosetests.xml +coverage.xml + +# Translations +*.mo +*.pot + +# Django stuff: +*.log + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +.DS_Store + +.idea/ +private_config.cfg +private_config_new.cfg +config.json +*.pyc \ No newline at end of file diff --git a/Procfile b/Procfile deleted file mode 100644 index 29e49ad..0000000 --- a/Procfile +++ /dev/null @@ -1 +0,0 @@ -web: python hello.py \ No newline at end of file diff --git a/README.md b/README.md index 79e38c2..4f60e04 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,21 @@ -Sample Python Web application +Cloud Foundry / Python / Flask Example ============================= -The sample is using [Flask microframework](http://flask.pocoo.org/) and is intented to test the Python support on [Pivotal's Cloud Foundry](https://run.pivotal.io/). +The sample is using [Flask microframework](http://flask.pocoo.org/) and is intented to demonstrate the Python support on [Pivotal's Cloud Foundry](https://run.pivotal.io/). -Deploy to Cloud Foundry +Deploy Version 1 (ultra basic, easy to understand) ----------------------- -```script -cf push -m 128M -b https://github.com/heroku/heroku-buildpack-python.git + +``` +cd version1 +cf push +``` + +Deploy Version 2 (cleaner, more idiomatic with manifests/templates, etc) +------------------------------- + ``` -or -```script -cf push -m 128M -b https://github.com/joshuamckenty/heroku-buildpack-python.git +cd version2 +cf push ``` -or -```script -cf push -m 128M -b https://github.com/ephoning/heroku-buildpack-python.git -```` -Notes ------ -2014/02/18: The offical Heroku buildpack seems not to be working with Cloud Foundry. diff --git a/hello.py b/hello.py deleted file mode 100644 index a492455..0000000 --- a/hello.py +++ /dev/null @@ -1,12 +0,0 @@ -import os -from flask import Flask - -app = Flask(__name__) - -@app.route('/') -def hello(): - return 'Hello World!' - -port = os.getenv('VCAP_APP_PORT', '5000') -if __name__ == "__main__": - app.run(host='0.0.0.0', port=int(port)) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 56eeb0c..0000000 --- a/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -Flask==0.10.1 \ No newline at end of file diff --git a/runtime.txt b/runtime.txt deleted file mode 100644 index 549b28a..0000000 --- a/runtime.txt +++ /dev/null @@ -1 +0,0 @@ -python-2.6.5 diff --git a/version1/Procfile b/version1/Procfile new file mode 100644 index 0000000..f8b9061 --- /dev/null +++ b/version1/Procfile @@ -0,0 +1 @@ +web: python hello-idiomatic.py diff --git a/version1/hello.py b/version1/hello.py new file mode 100644 index 0000000..4bd03df --- /dev/null +++ b/version1/hello.py @@ -0,0 +1,32 @@ +import os +import uuid +from flask import Flask + + +app = Flask(__name__) +my_uuid = str(uuid.uuid1()) +BLUE = "#0099FF" +GREEN = "#33CC33" + +COLOR = GREEN + +@app.route('/') +def hello(): + + + return """ + + + +

Hi, I'm GUID:
+ {}
+ + +

+ + + + """.format(COLOR,my_uuid,) + +if __name__ == "__main__": + app.run(debug=False,host='0.0.0.0', port=int(os.getenv('PORT', '5000'))) diff --git a/version1/requirements.txt b/version1/requirements.txt new file mode 100644 index 0000000..3ec68a0 --- /dev/null +++ b/version1/requirements.txt @@ -0,0 +1,6 @@ +Flask==0.10.1 +Jinja2==2.7.2 +MarkupSafe==0.19 +Werkzeug==0.9.4 +itsdangerous==0.24 +wsgiref==0.1.2 diff --git a/version2/hello-idiomatic.py b/version2/hello-idiomatic.py new file mode 100644 index 0000000..dd16f52 --- /dev/null +++ b/version2/hello-idiomatic.py @@ -0,0 +1,21 @@ +from __future__ import print_function +import os +import uuid +from flask import Flask, render_template +from cfenv import AppEnv + + +env = AppEnv() +app = Flask(__name__) +my_uuid = str(uuid.uuid1()) +BLUE = "#0099FF" +GREEN = "#33CC33" + +COLOR = GREEN + +@app.route('/') +def hello(): + return render_template("index.html",bgcolor=COLOR,guid=my_uuid) + +if __name__ == "__main__": + app.run(debug=False,host='0.0.0.0', port=env.port) diff --git a/version2/manifest.yml b/version2/manifest.yml new file mode 100644 index 0000000..28614cd --- /dev/null +++ b/version2/manifest.yml @@ -0,0 +1,8 @@ +--- +applications: +- name: hello-python-idiomatic-${random-word} + memory: 128M + buildpack: python_buildpack + domain: cfapps.io + command: python hello-idiomatic.py + timeout: 20 diff --git a/version2/requirements.txt b/version2/requirements.txt new file mode 100644 index 0000000..8563989 --- /dev/null +++ b/version2/requirements.txt @@ -0,0 +1,7 @@ +Flask==0.10.1 +Jinja2==2.7.2 +MarkupSafe==0.19 +Werkzeug==0.9.4 +itsdangerous==0.24 +wsgiref==0.1.2 +cfenv==0.4.0 \ No newline at end of file diff --git a/version2/templates/index.html b/version2/templates/index.html new file mode 100644 index 0000000..d035276 --- /dev/null +++ b/version2/templates/index.html @@ -0,0 +1,11 @@ + + + +

Hi, I'm GUID:
+ {{ guid }}
+ + +

+ + + \ No newline at end of file