This document describes how Python apps are detected and built. It includes details on components and configuration of build and run images too.
Python runtime images are layered on Docker's official Python image.
The following system packages are added to the runtime image:
- curl
- gnupg
- libpq-dev
- default-libmysqlclient-dev
- unixodbc-dev
- msodbcsql17
- libexpat1
- unzip
- libodbc1
- apt-transport-https
- swig3.0
- locales
gunicorn (a Python package) is also included.
The Python toolset is run when any of the following conditions are met:
requirements.txt
in root of reporuntime.txt
in root of repo- Files with
.py
extension in root of repo or in sub-directories if setDISABLE_RECURSIVE_LOOKUP=false
. requirements.txt
at specific path within the repo if setCUSTOM_REQUIREMENTSTXT_PATH
.
The Python conda is run when any of the following conditions are met:
- Conda environment file
environment.yml
orenvironment.yaml
is found in root of repo - Files with
.ipynb
extension in root of repo
The following process is applied for each build.
- Run custom command or script if specified by
PRE_BUILD_COMMAND
orPRE_BUILD_SCRIPT_PATH
. - Create python virtual environment if specified by
VIRTUALENV_NAME
. - Run
python -m pip install --cache-dir /usr/local/share/pip-cache --prefer-binary -r requirements.txt
ifrequirements.txt
exists in the root of repo or specified byCUSTOM_REQUIREMENTSTXT_PATH
. - Run
python setup.py install
ifsetup.py
exists. - Run python package commands and determine python package wheel.
- If
manage.py
is found in the root of the repomanage.py collectstatic
is run. However, ifDISABLE_COLLECTSTATIC
is set totrue
this step is skipped. - Compress virtual environment folder if specified by
compress_virtualenv
property key. - Run custom command or script if specified by
POST_BUILD_COMMAND
orPOST_BUILD_SCRIPT_PATH
.
The following process is applied for each build.
- Run custom command or script if specified by
PRE_BUILD_COMMAND
orPRE_BUILD_SCRIPT_PATH
. - Set up Conda virtual environemnt
conda env create --file $envFile
. - If
requirment.txt
exists in the root of repo or specified byCUSTOM_REQUIREMENTSTXT_PATH
, activate environemntconda activate $environmentPrefix
and runpip install --no-cache-dir -r requirements.txt
. - Run custom command or script if specified by
POST_BUILD_COMMAND
orPOST_BUILD_SCRIPT_PATH
.
The latest version of pip
is used to install dependencies.
The following process is applied to determine how to start an app.
- If user has specified a start script, run it.
- Else, find a WSGI module and run with gunicorn.
- Look for and run a directory containing a
wsgi.py
file (for Django). - Look for the following files in the root of the repo and an
app
class within them (for Flask and other WSGI frameworks).application.py
app.py
index.py
server.py
- Look for and run a directory containing a
To enable running gunicorn with multiple workers strategy and fully utilize the cores to improve performance
and prevent potential timeout/blocks from sync workers, add and set the environment variable PYTHON_ENABLE_GUNICORN_MULTIWORKERS=true
into the app settings.
In Azure Web Apps the version of the Python runtime which runs your app is
determined by the value of LinuxFxVersion
in your site config. See
../base_images.md
for how to modify this.
The Python project uses this release schedule, clarified further in
"Development Lifecycle". Oryx will support all releases in bugfix
status, i.e. 3.7.x
and 2.7.x
in early 2019; and 3.6 and later releases in
security
status.
We will provide notification twelve months prior to removing a release line; subscribe to Azure Updates to stay updated!
We will update the patch
version of supported major.minor
releases at
least once every 3 months, replacing the previous patch
version for that
release.