azure-functions-core-tools icon indicating copy to clipboard operation
azure-functions-core-tools copied to clipboard

Func Init Python V2 Docker

Open matferrari-msft opened this issue 3 years ago • 13 comments

The command func init --worker-runtime python -m V2 --docker generates a Dockerfile without the env variable AzureWebJobsFeatureFlags=EnableWorkerIndexing. This prevents the function from being indexed/run inside the container.

matferrari-msft avatar Feb 17 '23 16:02 matferrari-msft

FYI the feature flag was removed in https://github.com/Azure/azure-functions-host/issues/8847 and changes are rolling out very soon

ejizba avatar Feb 17 '23 19:02 ejizba

I just posted the following question on SO:

https://stackoverflow.com/questions/75519932/azure-function-python-model-2-in-docker-container

I think I ran into the exact same problem. (func --version = 4.0.4895)

MRuecklCC avatar Feb 21 '23 11:02 MRuecklCC

is this still not working by default?

fernandodelacalle avatar May 25 '23 08:05 fernandodelacalle

Maybe this isn't the place but I still can't get v2 to work at all in containers even with the AzureWebJobsFeatureFlags=EnableWorkerIndexing

jellis18 avatar Jul 19 '23 14:07 jellis18

@jellis18 If I remember correctly, you also need to add an env variable for the storage backend the runtime uses. I believe I used the emulator.

matferrari-msft avatar Jul 19 '23 14:07 matferrari-msft

@matferrari-msft is that this? AzureWebJobsStorage=UseDevelopmentStorage=true. If so, it still doesn't work. I'm just gonna use v1...

jellis18 avatar Jul 19 '23 14:07 jellis18

@jellis18 Yes, however, you would need to ensure that the emulator is actually accessible from within the container where the runtime is running. A potentially easier way is to just use a connection string. @ejizba @gavin-aguiar Are you able to provide any insights/guidance?

matferrari-msft avatar Jul 19 '23 14:07 matferrari-msft

Mine worked a after I added the following lines in my docker file

FROM mcr.microsoft.com/azure-functions/python:4-python3.10

ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
    AzureFunctionsJobHost__Logging__Console__IsEnabled=true \
    AzureWebJobsFeatureFlags=EnableWorkerIndexing \  # added by me 
    AzureWebJobsStorage='Add your conection string' #added by me 

COPY requirements.txt /
RUN pip install -r /requirements.txt

COPY . /home/site/wwwroot

docker run -it --rm -p 8080:80 image_name

flavian-anselmo avatar Jul 27 '23 11:07 flavian-anselmo

running into the same issue with python v2 in docker. can't get the functions to load image

litan1106 avatar Oct 19 '23 20:10 litan1106

Thanks @MRuecklCC for the SO posted Q, this is what worked for me to start the docker container locally

FROM mcr.microsoft.com/azure-functions/python:4-python3.11

ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
    AzureFunctionsJobHost__Logging__Console__IsEnabled=true \
    AzureWebJobsFeatureFlags=EnableWorkerIndexing \
    AzureWebJobsStorage="UseDevelopmentStorage=true"

COPY requirements.txt /
RUN pip install -r /requirements.txt

COPY . /home/site/wwwroot

These 2 lines are manually added

AzureWebJobsFeatureFlags=EnableWorkerIndexing \
AzureWebJobsStorage="UseDevelopmentStorage=true"

montaro avatar Nov 16 '23 16:11 montaro

I followed the suggested solutions, but still the functions don't get recognize, any other ideas?

yovelcohen avatar Feb 06 '24 20:02 yovelcohen

I tried with http trigger it was okay, but when I add blob trigger, it was not found.

musitafa0032 avatar Mar 21 '24 23:03 musitafa0032

I have the same problem:

image

santisossa avatar Aug 09 '24 15:08 santisossa

Same problem here using the v2 programming model, functions do not get recognized. Any comments from the maintainers (@matferrari-msft) on this? It's really frustrating since it is mentioned as a feature that we can use custom containers.

I am using blueprints and have one "function_app.py" file where all come together, e.g.

import azure.functions as func 
from src.functions.login_token_function import bp
from src.functions.users_jobs import uj
from src.functions.login_function import login_func
from src.functions.update_jobs import update_jobs_bp
from src.functions.new_job import new_jobs_bp
from src.functions.upload_pdf import up
from src.functions.create_pdf import gpdf

app = func.FunctionApp() 

app.register_functions(bp) 
app.register_functions(uj)
app.register_functions(login_func)
app.register_functions(update_jobs_bp)
app.register_functions(new_jobs_bp)
app.register_functions(up)
app.register_functions(gpdf)

This works fine without a custom container.

CloseChoice avatar Nov 09 '24 21:11 CloseChoice