Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a continuous delivery of a python function app deployed in Azure?

For the first time I deployed a Python function app to Azure using a deployment pipeline:

https://docs.microsoft.com/bs-latn-ba/azure/azure-functions/functions-how-to-azure-devops

The package is deployed to Azure using Kudu Zip deploy.

My http triggered function runs wonderfully locally (on Windows), but I have a 500 internal errors on Azure because it does not find the module requests.

Exception: ModuleNotFoundError: No module named 'requests'

imports of __init__.py:

import logging, requests, os
import azure.functions as func

If I remove the 'requests' dependency the function works on Azure (status 200).

The requests library is imported by the requirement.txt and copied to the .venv36/lib/site-packages/requests by the build pipeline.

So I am wondering if the virtual environment .venv36 that is built in the package is used by the function deployed in Azure. There is no indication about how to activate virtual environments in Azure.

like image 968
Anthony Brenelière Avatar asked Nov 14 '19 15:11

Anthony Brenelière


People also ask

What is continuous deployment in Azure?

Continuous delivery (CD) is the process of automating build, test, configuration, and deployment from a build to a production environment. A release pipeline can create multiple testing or staging environments to automate infrastructure creation and deploy new builds.


1 Answers

If you name your virtual env worker_venv as named in the documentation you linked, it should work (assuming you are using a Linux environment for your pipeline).

However, the Python Azure Functions documentation is to be updated very soon, and the recommended way would be to not deploy the entire virtual environment from your deployment pipeline. Instead, you'd want to install your packages in .python_packages/lib/site-packages.

You could do --

pip3.6 install --target .python_packages/lib/site-packages -r requirements.txt

Instead of --

python3.6 -m venv worker_venv
source worker_venv/bin/activate
pip3.6 install setuptools
pip3.6 install -r requirements.txt

And it should work fine.

like image 51
Ankit Kumar Avatar answered Oct 18 '22 11:10

Ankit Kumar