Azure / azure-functions-docker

This repo contains the base Docker images for working with azure functions
MIT License
267 stars 118 forks source link

Azure Function - Python -> warn: Host.Startup[0]. No job functions found. Try making your job classes and methods public. #987

Open girguy opened 1 year ago

girguy commented 1 year ago

I'm currently working on a simple Azure Function that's triggered by an HTTP request. I'm trying to run it within a Docker container, but I'm facing an issue where the function doesn't seem to be recognized. Here's the warning I receive in my logs:

warn: Host.Startup[0] No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.). info: Microsoft.Azure.WebJobs.Script.WebHost.WebScriptHostHttpRoutesManager[0] Initializing function HTTP routes No HTTP routes mapped

Azure function

import azure.functions as func
import logging

app = func.FunctionApp()

@app.route(route="HttpExample", auth_level=func.AuthLevel.ANONYMOUS)
def HttpExample(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')

    name = req.params.get('name')
    if not name:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            name = req_body.get('name')

    if name:
        return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
    else:
        return func.HttpResponse(
             "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
             status_code=200
        )

Docker file

# To enable ssh & remote debugging on app service change the base image to the one below
# FROM mcr.microsoft.com/azure-functions/python:4-python3.10-appservice
FROM mcr.microsoft.com/azure-functions/python:4-python3.10

ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
    AzureFunctionsJobHost__Logging__Console__IsEnabled=true

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

COPY . /home/site/wwwroot

Here are the lines I used to build and run the docker container docker build --tag ggirineza/azure_functions_image_test:v1.0.0 . docker run -p 8080:80 -it ggirineza/azure_functions_image_test:v1.0.0

My experience with Docker is fairly limited, though I have successfully deployed similar functions using AWS Lambda, which was a more intuitive process for me. But with Azure, I really don't get it honestly..

I would really appreciate some help.

ADR-007 commented 1 year ago

+1. I have the same problem, and already spent a lot of hours trying to run the "hello world" function in docker.

halyssonfreitas commented 11 months ago

Try to add: AzureWebJobsFeatureFlags=EnableWorkerIndexing

Like in exemple:

FROM mcr.microsoft.com/azure-functions/node:4-nightly-node18

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

COPY . /home/site/wwwroot

RUN cd /home/site/wwwroot && \
    npm install && \
    npm run build
halyssonfreitas commented 11 months ago

If you aren't using Docker, so try add "AzureWebJobsFeatureFlags": "EnableWorkerIndexing" in local.settings.json values.

sudharsan2020 commented 11 months ago

Please install azure-functions-core-tools-4 by stepping inside the Docker container and run the below commands. The default logs doesn't provide any useful information apart from saying No job functions found

Step inside your docker container using this:

sudo docker run -it -u 0  -p 15000:80  demo:latest /bin/bash

After stepping inside the container, then run the below commands to install the azure-functions-core-tools-4

apt update 
apt install -y curl
apt install -y gnupg
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-jammy-prod jammy main" > /etc/apt/sources.list.d/dotnetdev.list'
apt-get update
apt-get install azure-functions-core-tools-4

Then navigate to the project folder and manually run func start --verbose to identify the missing dependencies in an easier way.

Hope it helps!

jmelhus commented 10 months ago

Try to add: AzureWebJobsFeatureFlags=EnableWorkerIndexing

Like in exemple:

FROM mcr.microsoft.com/azure-functions/node:4-nightly-node18

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

COPY . /home/site/wwwroot

RUN cd /home/site/wwwroot && \
    npm install && \
    npm run build

this worked for me

lopez- commented 8 months ago

Please install azure-functions-core-tools-4 by stepping inside the Docker container and run the below commands. The default logs doesn't provide any useful information apart from saying No job functions found

Step inside your docker container using this:

sudo docker run -it -u 0  -p 15000:80  demo:latest /bin/bash

After stepping inside the container, then run the below commands to install the azure-functions-core-tools-4

apt update 
apt install -y curl
apt install -y gnupg
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-jammy-prod jammy main" > /etc/apt/sources.list.d/dotnetdev.list'
apt-get update
apt-get install azure-functions-core-tools-4

Then navigate to the project folder and manually run func start --verbose to identify the missing dependencies in an easier way.

Hope it helps!

@sudharsan2020 's suggestion did it for me. With the verbose logs I could see that the durable function's trigger was still pointing to 127.0.0.1 which doesn't resolve to azurite's container. The connection fails and the error just says "No job functions found". How I resolved it: