diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..a39d2b053 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,12 @@ +node_modules +npm-debug.log +Dockerfile* +docker-compose* +.dockerignore +.git +.gitignore +README.md +LICENSE +.vscode +__pycache__ +env diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..0f62521f9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,34 @@ +# Pull a pre-built alpine docker image with nginx and python3 installed +FROM tiangolo/uwsgi-nginx-flask:python3.6-alpine3.7 + +# Set the port on which the app runs; make both values the same. +# +# IMPORTANT: When deploying to Azure App Service, go to the App Service on the Azure +# portal, navigate to the Applications Settings blade, and create a setting named +# WEBSITES_PORT with a value that matches the port here (the Azure default is 80). +# You can also create a setting through the App Service Extension in VS Code. +ENV LISTEN_PORT=5000 +EXPOSE 5000 + +# Indicate where uwsgi.ini lives +ENV UWSGI_INI uwsgi.ini + +# Tell nginx where static files live. Typically, developers place static files for +# multiple apps in a shared folder, but for the purposes here we can use the one +# app's folder. Note that when multiple apps share a folder, you should create subfolders +# with the same name as the app underneath "static" so there aren't any collisions +# when all those static files are collected together. +ENV STATIC_URL /hello_app/static + +# Set the folder where uwsgi looks for the app +WORKDIR /hello_app + +# Copy the app contents to the image +COPY . /hello_app + +# If you have additional requirements beyond Flask (which is included in the +# base image), generate a requirements.txt file with pip freeze and uncomment +# the next three lines. +#COPY requirements.txt / +#RUN pip install --no-cache-dir -U pip +#RUN pip install --no-cache-dir -r /requirements.txt diff --git a/README.md b/README.md index 46ce7f06d..ac2378d7d 100644 --- a/README.md +++ b/README.md @@ -1,7 +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. -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). +It also contains 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. +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). # Contributing diff --git a/uwsgi.ini b/uwsgi.ini new file mode 100644 index 000000000..0326d2899 --- /dev/null +++ b/uwsgi.ini @@ -0,0 +1,7 @@ +[uwsgi] +module = hello_app.webapp +callable = app +uid = 1000 +master = true +threads = 2 +processes = 4