Docker容器中的Azure函数Python模型2

iyr7buue  于 2023-03-03  发布在  Docker
关注(0)|答案(1)|浏览(129)

我无法得到一个运行以下设置的最小工作示例:

  • Docker容器中的 Azure 功能
  • Python作为语言,特别是“新Python编程模型V2”

我按照这里的说明操作,但添加了V2标志,具体如下:

# init directory
 func init --worker-runtime python --docker -m V2
 # build docker image
 docker build -t foo .
 # run functions locally
 docker run -p 80:80 foo

无论我尝试了什么,运行时似乎都无法获取自动生成的http触发器函数

# function_app.py (autogenerated by func init ...) 

import azure.functions as func

app = func.FunctionApp()

@app.function_name(name="HttpTrigger1")
@app.route(route="hello") # HTTP Trigger
def test_function(req: func.HttpRequest) -> func.HttpResponse:
    return func.HttpResponse("HttpTrigger1 function processed a request!!!")

我认为日志的相关部分是:

info: Host.Startup[327]
      1 functions found
info: Host.Startup[315]
      0 functions loaded
info: Host.Startup[0]
      Generating 0 job function(s)
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

因为当我使用“编程模型V1”时,Microsoft.Azure.WebJobs.Script.WebHost.WebScriptHostHttpRoutesManager实际上会打印一些关于Map路线的信息。
我该怎么解决这个问题?目前不支持这个吗?

ygya80vv

ygya80vv1#

看起来enter link description here上正在进行更改。有了这里的注解,我能够通过更改自动生成的dockerfile中的环境变量来使它工作。
修改的停靠文件:

# 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 \
    AzureWebJobsFeatureFlags=EnableWorkerIndexing \ # added by me
    AzureWebJobsStorage=UseDevelopmentStorage=true # added by me 

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

COPY . /home/site/wwwroot

相关问题