From 40faec108acd9af66f5da8a568960ad4a628fa1f Mon Sep 17 00:00:00 2001 From: Cephas Lin Date: Fri, 13 Jul 2018 17:00:15 +0200 Subject: [PATCH 01/13] convert to container quickstart --- Dockerfile | 6 ++ README.md | 8 +-- main.py => app/main.py | 0 ptvs_virtualenv_proxy.py | 122 --------------------------------------- requirements.txt | 1 - web.2.7.config | 46 --------------- web.3.4.config | 44 -------------- 7 files changed, 9 insertions(+), 218 deletions(-) create mode 100644 Dockerfile rename main.py => app/main.py (100%) delete mode 100644 ptvs_virtualenv_proxy.py delete mode 100644 requirements.txt delete mode 100644 web.2.7.config delete mode 100644 web.3.4.config diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..87c51c948 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM tiangolo/uwsgi-nginx-flask:python3.6-alpine3.7 + +ENV LISTEN_PORT=8000 +EXPOSE 8000 + +COPY /app /app \ No newline at end of file diff --git a/README.md b/README.md index df934860e..fb439cea3 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,8 @@ -# Python Flask app on Azure App Service Web +# Python Flask app on Azure Web App for Containers -This is a minimal sample app that demonstrates how to run a Python Flask application on Azure App Service Web. +This is a minimal sample app that demonstrates how to run a Python Flask application on Azure Web App for Containers. -This repository can directly be deployed to Azure App Service. - -For more information, please see the [Python on App Service Quickstart docs](https://docs.microsoft.com/en-us/azure/app-service-web/app-service-web-get-started-python). +For more information, please see the [Python on App Service Quickstart docs](https://docs.microsoft.com/en-us/azure/app-service/containers/quickstart-python). # Contributing diff --git a/main.py b/app/main.py similarity index 100% rename from main.py rename to app/main.py diff --git a/ptvs_virtualenv_proxy.py b/ptvs_virtualenv_proxy.py deleted file mode 100644 index a4a412980..000000000 --- a/ptvs_virtualenv_proxy.py +++ /dev/null @@ -1,122 +0,0 @@ -# ############################################################################ - # - # Copyright (c) Microsoft Corporation. - # - # This source code is subject to terms and conditions of the Apache License, Version 2.0. A - # copy of the license can be found in the License.html file at the root of this distribution. If - # you cannot locate the Apache License, Version 2.0, please send an email to - # vspython@microsoft.com. By using this source code in any fashion, you are agreeing to be bound - # by the terms of the Apache License, Version 2.0. - # - # You must not remove this notice, or any other, from this software. - # - # ########################################################################### - -import datetime -import os -import sys -import traceback - -if sys.version_info[0] == 3: - def to_str(value): - return value.decode(sys.getfilesystemencoding()) - - def execfile(path, global_dict): - """Execute a file""" - with open(path, 'r') as f: - code = f.read() - code = code.replace('\r\n', '\n') + '\n' - exec(code, global_dict) -else: - def to_str(value): - return value.encode(sys.getfilesystemencoding()) - -def log(txt): - """Logs fatal errors to a log file if WSGI_LOG env var is defined""" - log_file = os.environ.get('WSGI_LOG') - if log_file: - f = open(log_file, 'a+') - try: - f.write('%s: %s' % (datetime.datetime.now(), txt)) - finally: - f.close() - -ptvsd_secret = os.getenv('WSGI_PTVSD_SECRET') -if ptvsd_secret: - log('Enabling ptvsd ...\n') - try: - import ptvsd - try: - ptvsd.enable_attach(ptvsd_secret) - log('ptvsd enabled.\n') - except: - log('ptvsd.enable_attach failed\n') - except ImportError: - log('error importing ptvsd.\n') - -def get_wsgi_handler(handler_name): - if not handler_name: - raise Exception('WSGI_ALT_VIRTUALENV_HANDLER env var must be set') - - if not isinstance(handler_name, str): - handler_name = to_str(handler_name) - - module_name, _, callable_name = handler_name.rpartition('.') - should_call = callable_name.endswith('()') - callable_name = callable_name[:-2] if should_call else callable_name - name_list = [(callable_name, should_call)] - handler = None - last_tb = '' - - while module_name: - try: - handler = __import__(module_name, fromlist=[name_list[0][0]]) - last_tb = '' - for name, should_call in name_list: - handler = getattr(handler, name) - if should_call: - handler = handler() - break - except ImportError: - module_name, _, callable_name = module_name.rpartition('.') - should_call = callable_name.endswith('()') - callable_name = callable_name[:-2] if should_call else callable_name - name_list.insert(0, (callable_name, should_call)) - handler = None - last_tb = ': ' + traceback.format_exc() - - if handler is None: - raise ValueError('"%s" could not be imported%s' % (handler_name, last_tb)) - - return handler - -activate_this = os.getenv('WSGI_ALT_VIRTUALENV_ACTIVATE_THIS') -if not activate_this: - raise Exception('WSGI_ALT_VIRTUALENV_ACTIVATE_THIS is not set') - -def get_virtualenv_handler(): - log('Activating virtualenv with %s\n' % activate_this) - execfile(activate_this, dict(__file__=activate_this)) - - log('Getting handler %s\n' % os.getenv('WSGI_ALT_VIRTUALENV_HANDLER')) - handler = get_wsgi_handler(os.getenv('WSGI_ALT_VIRTUALENV_HANDLER')) - log('Got handler: %r\n' % handler) - return handler - -def get_venv_handler(): - log('Activating venv with executable at %s\n' % activate_this) - import site - sys.executable = activate_this - old_sys_path, sys.path = sys.path, [] - - site.main() - - sys.path.insert(0, '') - for item in old_sys_path: - if item not in sys.path: - sys.path.append(item) - - log('Getting handler %s\n' % os.getenv('WSGI_ALT_VIRTUALENV_HANDLER')) - handler = get_wsgi_handler(os.getenv('WSGI_ALT_VIRTUALENV_HANDLER')) - log('Got handler: %r\n' % handler) - return handler \ No newline at end of file diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 6aef94caf..000000000 --- a/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -Flask==0.12.1 diff --git a/web.2.7.config b/web.2.7.config deleted file mode 100644 index 909a6f6e4..000000000 --- a/web.2.7.config +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/web.3.4.config b/web.3.4.config deleted file mode 100644 index 1552b7fd1..000000000 --- a/web.3.4.config +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From 3d19a6ee79327906728f66a71f620a6d1e78bfea Mon Sep 17 00:00:00 2001 From: Cephas Lin Date: Mon, 20 Aug 2018 12:40:08 +0200 Subject: [PATCH 02/13] built-in Linux image changes --- Dockerfile | 6 ------ README.md | 4 ++-- app/main.py | 9 --------- application.py | 6 ++++++ requirements.txt | 6 ++++++ 5 files changed, 14 insertions(+), 17 deletions(-) delete mode 100644 Dockerfile delete mode 100644 app/main.py create mode 100644 application.py create mode 100644 requirements.txt diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 87c51c948..000000000 --- a/Dockerfile +++ /dev/null @@ -1,6 +0,0 @@ -FROM tiangolo/uwsgi-nginx-flask:python3.6-alpine3.7 - -ENV LISTEN_PORT=8000 -EXPOSE 8000 - -COPY /app /app \ No newline at end of file diff --git a/README.md b/README.md index fb439cea3..b38c45a36 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Python Flask app on Azure Web App for Containers -This is a minimal sample app that demonstrates how to run a Python Flask application on Azure Web App for Containers. +This is a minimal sample app that demonstrates how to run a Python Flask application on Azure App Service on Linux. -For more information, please see the [Python on App Service Quickstart docs](https://docs.microsoft.com/en-us/azure/app-service/containers/quickstart-python). +For more information, please see the [Python on App Service quickstart](https://docs.microsoft.com/en-us/azure/app-service/containers/quickstart-python). # Contributing diff --git a/app/main.py b/app/main.py deleted file mode 100644 index a1897c800..000000000 --- a/app/main.py +++ /dev/null @@ -1,9 +0,0 @@ -from flask import Flask -app = Flask(__name__) - -@app.route('/') -def hello_world(): - return 'Hello, World!' - -if __name__ == '__main__': - app.run() diff --git a/application.py b/application.py new file mode 100644 index 000000000..a86beaa6d --- /dev/null +++ b/application.py @@ -0,0 +1,6 @@ +from flask import Flask +app = Flask(__name__) + +@app.route("/") +def hello(): + return "Hello World!" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 000000000..404d3cf1f --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +click==6.7 +Flask==1.0.2 +itsdangerous==0.24 +Jinja2==2.10 +MarkupSafe==1.0 +Werkzeug==0.14.1 \ No newline at end of file From b4f4a930a39b8ec19da1cdaf3f2396de81b5625a Mon Sep 17 00:00:00 2001 From: Scott Clay Date: Fri, 5 Oct 2018 10:59:45 +0100 Subject: [PATCH 03/13] Made application.py PEP8 complient by fixing two lines for E302 and W292. --- application.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/application.py b/application.py index a86beaa6d..591872ebf 100644 --- a/application.py +++ b/application.py @@ -1,6 +1,7 @@ from flask import Flask app = Flask(__name__) + @app.route("/") def hello(): - return "Hello World!" \ No newline at end of file + return "Hello World!" From e1abf8b7a3bc256bf20454f22a119808b4c7abe9 Mon Sep 17 00:00:00 2001 From: Cephas Lin Date: Mon, 8 Apr 2019 18:47:24 +0200 Subject: [PATCH 04/13] Update README.md --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b38c45a36..d28e78d23 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,13 @@ -# Python Flask app on Azure Web App for Containers +--- +topic: Python Flask sample for Azure App Service (Linux) +languages: + - python +products: + - Azure App Service + - Azure Web Apps +--- + +# Python Flask sample for Azure App Service (Linux) This is a minimal sample app that demonstrates how to run a Python Flask application on Azure App Service on Linux. From d43959675ea729f02aa340d52929158b6d0abbf9 Mon Sep 17 00:00:00 2001 From: "Den (Microsoft)" <33675759+dendeli-msft@users.noreply.github.com> Date: Wed, 17 Jul 2019 15:36:28 -0700 Subject: [PATCH 05/13] Update README.md --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d28e78d23..d1ab922be 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,11 @@ --- -topic: Python Flask sample for Azure App Service (Linux) +page_type: sample +description: "This is a minimal sample app that demonstrates how to run a Python Flask application on Azure App Service on Linux." languages: - - python +- python products: - - Azure App Service - - Azure Web Apps +- azure +- azure-app-service --- # Python Flask sample for Azure App Service (Linux) From 63e366cfeb32f9ce78fc403f632fcac67904b29a Mon Sep 17 00:00:00 2001 From: "Den (Microsoft)" <33675759+dendeli-msft@users.noreply.github.com> Date: Wed, 17 Jul 2019 15:37:09 -0700 Subject: [PATCH 06/13] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d1ab922be..8487a9c8b 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ products: This is a minimal sample app that demonstrates how to run a Python Flask application on Azure App Service on Linux. -For more information, please see the [Python on App Service quickstart](https://docs.microsoft.com/en-us/azure/app-service/containers/quickstart-python). +For more information, please see the [Python on App Service quickstart](https://docs.microsoft.com/azure/app-service/containers/quickstart-python). # Contributing From f1583e8aaf085c72054a971af9d2bd42b7d030cb Mon Sep 17 00:00:00 2001 From: docs <33675759+docs-product@users.noreply.github.com> Date: Tue, 15 Oct 2019 15:27:47 -0700 Subject: [PATCH 07/13] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8487a9c8b..3f21465ef 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,6 @@ This is a minimal sample app that demonstrates how to run a Python Flask applica For more information, please see the [Python on App Service quickstart](https://docs.microsoft.com/azure/app-service/containers/quickstart-python). -# Contributing +## Contributing This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. From 7842644d356e9223576a2e82de58ebf07992f423 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 1 Nov 2019 13:51:35 +0000 Subject: [PATCH 08/13] Bump werkzeug from 0.14.1 to 0.15.3 Bumps [werkzeug](https://github.com/pallets/werkzeug) from 0.14.1 to 0.15.3. - [Release notes](https://github.com/pallets/werkzeug/releases) - [Changelog](https://github.com/pallets/werkzeug/blob/master/CHANGES.rst) - [Commits](https://github.com/pallets/werkzeug/compare/0.14.1...0.15.3) Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 404d3cf1f..99cb23149 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,4 @@ Flask==1.0.2 itsdangerous==0.24 Jinja2==2.10 MarkupSafe==1.0 -Werkzeug==0.14.1 \ No newline at end of file +Werkzeug==0.15.3 \ No newline at end of file From c133e23b18245bbbfa197187f5cd1c45db535ca9 Mon Sep 17 00:00:00 2001 From: Kraig Brockschmidt Date: Tue, 22 Sep 2020 10:07:50 -0700 Subject: [PATCH 09/13] Update requirements.txt --- requirements.txt | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/requirements.txt b/requirements.txt index 99cb23149..32e2d2715 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1 @@ -click==6.7 -Flask==1.0.2 -itsdangerous==0.24 -Jinja2==2.10 -MarkupSafe==1.0 -Werkzeug==0.15.3 \ No newline at end of file +Flask>=1.0,<=1.1.2 From 168cd1e822c72cc31f58d6470bea609c2be65207 Mon Sep 17 00:00:00 2001 From: Kraig Brockschmidt Date: Tue, 22 Sep 2020 14:29:34 -0700 Subject: [PATCH 10/13] Fix phrase to match screenshots --- application.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application.py b/application.py index 591872ebf..3cf7d9387 100644 --- a/application.py +++ b/application.py @@ -4,4 +4,4 @@ @app.route("/") def hello(): - return "Hello World!" + return "Hello, World!" From 9569abaf6f39ae72496e9641c6c57f4f97ae4294 Mon Sep 17 00:00:00 2001 From: Kraig Brockschmidt Date: Tue, 22 Sep 2020 16:58:26 -0700 Subject: [PATCH 11/13] Rename application.py to app.py Doing so allows the associated article to drop the set FLASK_APP step for simplicity. Also update .gitignore for VS Code, and update the readme. --- .gitignore | 5 +++++ README.md | 6 +++--- application.py => app.py | 1 - 3 files changed, 8 insertions(+), 4 deletions(-) rename application.py => app.py (99%) diff --git a/.gitignore b/.gitignore index 72364f99f..441a11ffd 100644 --- a/.gitignore +++ b/.gitignore @@ -81,9 +81,14 @@ celerybeat-schedule # virtualenv venv/ ENV/ +.venv/ # Spyder project settings .spyderproject # Rope project settings .ropeproject + +# Visual Studio Code +.vscode/ + diff --git a/README.md b/README.md index 3f21465ef..8a2e9e91e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ --- page_type: sample -description: "This is a minimal sample app that demonstrates how to run a Python Flask application on Azure App Service on Linux." +description: "A minimal sample app that can be used to demonstrate deploying Flask apps to Azure App Service on Linux." languages: - python products: @@ -10,9 +10,9 @@ products: # Python Flask sample for Azure App Service (Linux) -This is a minimal sample app that demonstrates how to run a Python Flask application on Azure App Service on Linux. +This is a minimal Flask app that can be deployed to Azure App Service on Linux. -For more information, please see the [Python on App Service quickstart](https://docs.microsoft.com/azure/app-service/containers/quickstart-python). +For instructions on running and deploying the code, see [Quickstart: Create a Python app in Azure App Service on Linux](https://docs.microsoft.com/azure/app-service/quickstart-python). ## Contributing diff --git a/application.py b/app.py similarity index 99% rename from application.py rename to app.py index 3cf7d9387..7f8a1f2e8 100644 --- a/application.py +++ b/app.py @@ -1,7 +1,6 @@ from flask import Flask app = Flask(__name__) - @app.route("/") def hello(): return "Hello, World!" From 3f4653bca1a5709d9436c8dc32c41f82f90e2add Mon Sep 17 00:00:00 2001 From: Chris Harris Date: Thu, 31 Mar 2022 12:09:30 -0700 Subject: [PATCH 12/13] Update version to Flask 2 Flask 1 returns an import error [cannot import name 'escape' from 'jinja2'] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 32e2d2715..a246e0f91 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -Flask>=1.0,<=1.1.2 +Flask>=2.0,<=2.1.1 From 8239188b516e8bf3882d02094d81c477b29c5c66 Mon Sep 17 00:00:00 2001 From: JimacoMS4 <84105740+JimacoMS4@users.noreply.github.com> Date: Thu, 21 Dec 2023 14:52:41 -0800 Subject: [PATCH 13/13] Remove versioning from Flask in requiremnts.txt to get rid of Werkzeug version bug. This is a simple app and doesn't need to be pinned to a version --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index a246e0f91..e3e9a71d9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -Flask>=2.0,<=2.1.1 +Flask