From bde094e42b3c49fdee8299010f869590acfc38a1 Mon Sep 17 00:00:00 2001 From: Matt Cowger Date: Mon, 14 Apr 2014 15:49:22 -0700 Subject: [PATCH 01/11] Basic --- hello.py | 8 ++++++-- requirements.txt | 7 ++++++- runtime.txt | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/hello.py b/hello.py index a492455..67930df 100644 --- a/hello.py +++ b/hello.py @@ -1,12 +1,16 @@ import os +import pprint +import logging from flask import Flask app = Flask(__name__) +logging.basicConfig(level=logging.DEBUG) + @app.route('/') def hello(): - return 'Hello World!' + return 'Hello World!\n' 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 + app.run(host='0.0.0.0', port=int(port)) diff --git a/requirements.txt b/requirements.txt index 56eeb0c..3ec68a0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,6 @@ -Flask==0.10.1 \ No newline at end of file +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/runtime.txt b/runtime.txt index 549b28a..dd6a7de 100644 --- a/runtime.txt +++ b/runtime.txt @@ -1 +1 @@ -python-2.6.5 +python-2.7.5 From 3ea42e9836d54a85ddaa9454d38fec6b2700a384 Mon Sep 17 00:00:00 2001 From: Matt Cowger Date: Tue, 6 Jan 2015 13:56:33 -0800 Subject: [PATCH 02/11] Updates --- hello.py | 28 +++++++++++++++++++++------- runtime.txt | 1 - 2 files changed, 21 insertions(+), 8 deletions(-) delete mode 100644 runtime.txt diff --git a/hello.py b/hello.py index 67930df..6327952 100644 --- a/hello.py +++ b/hello.py @@ -1,16 +1,30 @@ import os -import pprint -import logging +import uuid from flask import Flask - app = Flask(__name__) +my_uuid = str(uuid.uuid1()) +BLUE = "#0099FF" +GREEN = "#33CC33" + + + +COLOR = GREEN -logging.basicConfig(level=logging.DEBUG) @app.route('/') def hello(): - return 'Hello World!\n' + + return """ + + + +

Hi, I'm GUID:
+ {} +

+ + + + """.format(COLOR,my_uuid) -port = os.getenv('VCAP_APP_PORT', '5000') if __name__ == "__main__": - app.run(host='0.0.0.0', port=int(port)) + app.run(host='0.0.0.0', port=int(os.getenv('VCAP_APP_PORT', '5000'))) diff --git a/runtime.txt b/runtime.txt deleted file mode 100644 index dd6a7de..0000000 --- a/runtime.txt +++ /dev/null @@ -1 +0,0 @@ -python-2.7.5 From 8f02c009178066b45b207872bb83e0952dfc0a47 Mon Sep 17 00:00:00 2001 From: Matt Cowger Date: Mon, 13 Apr 2015 08:00:42 -0700 Subject: [PATCH 03/11] Add ignore file --- .gitignore | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 .gitignore 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 From 5055d0227b21c742386b8fc2249d3bb6630174e7 Mon Sep 17 00:00:00 2001 From: Matt Cowger Date: Mon, 13 Apr 2015 08:16:34 -0700 Subject: [PATCH 04/11] Replaced procfile with manifest --- Procfile | 1 - manifest.yml | 9 +++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) delete mode 100644 Procfile create mode 100644 manifest.yml 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/manifest.yml b/manifest.yml new file mode 100644 index 0000000..2f4e4e1 --- /dev/null +++ b/manifest.yml @@ -0,0 +1,9 @@ +--- +applications: +- name: python-hello-mcowger + memory: 128M + no-route: false + host: python-hello-mcowger + instances: 1 + buildpack: python_buildpack + command: python hello.py From 9b31808a4205d1ac76ea8d5708a9bb45ddcb259f Mon Sep 17 00:00:00 2001 From: Matt Cowger Date: Tue, 14 Apr 2015 21:26:07 -0700 Subject: [PATCH 05/11] Go back to a procfile, and add directions for a BG deployment. --- Procfile | 1 + blue-green-deploy.sh | 0 hello.py | 7 ++----- manifest.yml | 9 --------- 4 files changed, 3 insertions(+), 14 deletions(-) create mode 100644 Procfile create mode 100644 blue-green-deploy.sh delete mode 100644 manifest.yml diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..8741ed9 --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: python hello.py diff --git a/blue-green-deploy.sh b/blue-green-deploy.sh new file mode 100644 index 0000000..e69de29 diff --git a/hello.py b/hello.py index 6327952..df1e51e 100644 --- a/hello.py +++ b/hello.py @@ -6,14 +6,11 @@ BLUE = "#0099FF" GREEN = "#33CC33" - - -COLOR = GREEN - +COLOR = BLUE @app.route('/') def hello(): - + return """ diff --git a/manifest.yml b/manifest.yml deleted file mode 100644 index 2f4e4e1..0000000 --- a/manifest.yml +++ /dev/null @@ -1,9 +0,0 @@ ---- -applications: -- name: python-hello-mcowger - memory: 128M - no-route: false - host: python-hello-mcowger - instances: 1 - buildpack: python_buildpack - command: python hello.py From e056935262abd4413ba61a997c1d1312a8c79307 Mon Sep 17 00:00:00 2001 From: Matt Cowger Date: Wed, 10 Jun 2015 11:40:21 -0700 Subject: [PATCH 06/11] remove reference to heroku BP --- README.md | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 79e38c2..6783008 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,18 @@ Sample Python Web application -============================= - -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 test the Python support on [Pivotal's Cloud Foundry](https://run.pivotal.io/). +````` Deploy to Cloud Foundry ----------------------- ```script -cf push -m 128M -b https://github.com/heroku/heroku-buildpack-python.git +cf push -m 128M ``` or ```script -cf push -m 128M -b https://github.com/joshuamckenty/heroku-buildpack-python.git +cf push -m 128M ``` or ```script -cf push -m 128M -b https://github.com/ephoning/heroku-buildpack-python.git +cf push -m 128M ```` - -Notes ------ -2014/02/18: The offical Heroku buildpack seems not to be working with Cloud Foundry. From 7009a52ebbd08f0c53a0de7fd3e8f18220e2b9fd Mon Sep 17 00:00:00 2001 From: Matt Cowger Date: Fri, 17 Jul 2015 11:14:27 +0200 Subject: [PATCH 07/11] Fix small bug --- blue-green-deploy.sh | 0 hello.py | 7 ++++--- 2 files changed, 4 insertions(+), 3 deletions(-) delete mode 100644 blue-green-deploy.sh diff --git a/blue-green-deploy.sh b/blue-green-deploy.sh deleted file mode 100644 index e69de29..0000000 diff --git a/hello.py b/hello.py index df1e51e..e60d6c2 100644 --- a/hello.py +++ b/hello.py @@ -10,13 +10,14 @@ @app.route('/') def hello(): - + return """

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

@@ -24,4 +25,4 @@ def hello(): """.format(COLOR,my_uuid) if __name__ == "__main__": - app.run(host='0.0.0.0', port=int(os.getenv('VCAP_APP_PORT', '5000'))) + app.run(debug=True,host='0.0.0.0', port=int(os.getenv('VCAP_APP_PORT', '5000'))) From d27f0024072aa834d1db9a2c777fdc22cc46ca20 Mon Sep 17 00:00:00 2001 From: Matt Cowger Date: Wed, 9 Sep 2015 11:11:31 -0700 Subject: [PATCH 08/11] Update --- hello.py | 32 ++++++++++++++++++-------------- requirements.txt | 1 + 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/hello.py b/hello.py index e60d6c2..7238919 100644 --- a/hello.py +++ b/hello.py @@ -1,28 +1,32 @@ import os import uuid from flask import Flask + + app = Flask(__name__) my_uuid = str(uuid.uuid1()) BLUE = "#0099FF" GREEN = "#33CC33" -COLOR = BLUE +COLOR = GREEN @app.route('/') def hello(): - - return """ - - - -

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

- - - - """.format(COLOR,my_uuid) + + + return """ + + + +

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

+ + + + """.format(COLOR,my_uuid,) if __name__ == "__main__": app.run(debug=True,host='0.0.0.0', port=int(os.getenv('VCAP_APP_PORT', '5000'))) diff --git a/requirements.txt b/requirements.txt index 3ec68a0..72f20ec 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ MarkupSafe==0.19 Werkzeug==0.9.4 itsdangerous==0.24 wsgiref==0.1.2 +redis \ No newline at end of file From 369f516ad35e7684ac8d91c9095cf0c8c92afde9 Mon Sep 17 00:00:00 2001 From: Matt Cowger Date: Thu, 29 Oct 2015 11:18:42 -0700 Subject: [PATCH 09/11] change to use PORT rather than VCAP_APP_PORT now that Diego is live in PWS --- hello.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hello.py b/hello.py index 7238919..4bd03df 100644 --- a/hello.py +++ b/hello.py @@ -29,4 +29,4 @@ def hello(): """.format(COLOR,my_uuid,) if __name__ == "__main__": - app.run(debug=True,host='0.0.0.0', port=int(os.getenv('VCAP_APP_PORT', '5000'))) + app.run(debug=False,host='0.0.0.0', port=int(os.getenv('PORT', '5000'))) From f3f8e0035410f49d6ace6433f22408708f8afe84 Mon Sep 17 00:00:00 2001 From: Matt Cowger Date: Thu, 3 Dec 2015 10:18:22 +1100 Subject: [PATCH 10/11] Moved to 2 versions --- hello-idiomatic.py | 0 templates/index.html | 10 ++++++++++ version1/Procfile | 1 + version1/hello.py | 32 ++++++++++++++++++++++++++++++++ version1/requirements.txt | 6 ++++++ version2/hello-idiomatic.py | 21 +++++++++++++++++++++ version2/manifest.yml | 8 ++++++++ version2/requirements.txt | 7 +++++++ version2/templates/index.html | 11 +++++++++++ 9 files changed, 96 insertions(+) create mode 100644 hello-idiomatic.py create mode 100644 templates/index.html create mode 100644 version1/Procfile create mode 100644 version1/hello.py create mode 100644 version1/requirements.txt create mode 100644 version2/hello-idiomatic.py create mode 100644 version2/manifest.yml create mode 100644 version2/requirements.txt create mode 100644 version2/templates/index.html diff --git a/hello-idiomatic.py b/hello-idiomatic.py new file mode 100644 index 0000000..e69de29 diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..566549b --- /dev/null +++ b/templates/index.html @@ -0,0 +1,10 @@ + + + + + Title + + + + + \ No newline at end of file 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 From ffdd6caf81de4b4a3cf77cd5a9ec0d13721f751a Mon Sep 17 00:00:00 2001 From: Matt Cowger Date: Fri, 4 Dec 2015 10:57:23 +1100 Subject: [PATCH 11/11] Cleanup directory structure and update README --- Procfile | 1 - README.md | 31 +++++++++++++++++-------------- hello-idiomatic.py | 0 hello.py | 32 -------------------------------- requirements.txt | 7 ------- templates/index.html | 10 ---------- 6 files changed, 17 insertions(+), 64 deletions(-) delete mode 100644 Procfile delete mode 100644 hello-idiomatic.py delete mode 100644 hello.py delete mode 100644 requirements.txt delete mode 100644 templates/index.html diff --git a/Procfile b/Procfile deleted file mode 100644 index 8741ed9..0000000 --- a/Procfile +++ /dev/null @@ -1 +0,0 @@ -web: python hello.py diff --git a/README.md b/README.md index 6783008..4f60e04 100644 --- a/README.md +++ b/README.md @@ -1,18 +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/). -````` -Deploy to Cloud Foundry +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 Version 1 (ultra basic, easy to understand) ----------------------- -```script -cf push -m 128M + ``` -or -```script -cf push -m 128M +cd version1 +cf push ``` -or -```script -cf push -m 128M -```` + +Deploy Version 2 (cleaner, more idiomatic with manifests/templates, etc) +------------------------------- + +``` +cd version2 +cf push +``` + diff --git a/hello-idiomatic.py b/hello-idiomatic.py deleted file mode 100644 index e69de29..0000000 diff --git a/hello.py b/hello.py deleted file mode 100644 index 4bd03df..0000000 --- a/hello.py +++ /dev/null @@ -1,32 +0,0 @@ -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/requirements.txt b/requirements.txt deleted file mode 100644 index 72f20ec..0000000 --- a/requirements.txt +++ /dev/null @@ -1,7 +0,0 @@ -Flask==0.10.1 -Jinja2==2.7.2 -MarkupSafe==0.19 -Werkzeug==0.9.4 -itsdangerous==0.24 -wsgiref==0.1.2 -redis \ No newline at end of file diff --git a/templates/index.html b/templates/index.html deleted file mode 100644 index 566549b..0000000 --- a/templates/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - Title - - - - - \ No newline at end of file