Skip to content

Commit

Permalink
Adding startup shim for App Service on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
kraigb committed Oct 18, 2018
1 parent 5cea79f commit 525a7f9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
This sample contains the completed program from the tutorial, [Using Flask in Visual Studio Code](https://code.visualstudio.com/docs/python/tutorial-flask). Intermediate steps are not included.

It also contains the Dockerfile and uwsgi.ini files necessary to build a container with a production server. The resulting image works both locally and when deployed to Azure App Service.
It also contains the Dockerfile and uwsgi.ini files necessary to build a container with a production server. The resulting image works both locally and when deployed to Azure App Service. See [Deploy Python using Docker containers](https://code.visualstudio.com/docs/python/tutorial-deploy-containers).

The `startup.py` file, for its part, is specifically for deploying to Azure App Service on Linux without containers. Because the app code is in its own *module* in the `hello_app` folder (which has an `__init__.py`), trying to start the Gunicorn server within App Service on Linux produces an "Attempted relative import in non-package" error. The `startup.py` file, therefore, is just a shim to import the app object from the `hello_app` module, which then allows you to use startup:app in the Gunicorn command line (see `startup.txt`).

Contributions to the sample are welcome. When submitting changes, also consider submitting matching changes to the tutorial, the source file for which is [tutorial-flask.md](https://github.com/Microsoft/vscode-docs/blob/master/docs/python/tutorial-flask.md).

Expand Down
10 changes: 10 additions & 0 deletions startup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# In this sample, the Flask app object is contained within the hello_app *module*;
# that is, hello_app contains an __init__.py along with relative imports. Because
# of this structure, a file like webapp.py cannot be run directly as the startup
# file through Gunicorn; the result is "Attempted relative import in non-package".
#
# The solution is to provide a simple alternate startup file, like this present
# startup.py, that just imports the app object. You can then just specify
# startup:app in the Gunicorn command.

from hello_app.webapp import app
1 change: 1 addition & 0 deletions startup.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gunicorn --bind=0.0.0.0 --workers=4 startup:app

0 comments on commit 525a7f9

Please sign in to comment.