Azure / azure-functions-core-tools

Command line tools for Azure Functions
MIT License
1.3k stars 430 forks source link

Environment variable "AzureWebJobsScriptRoot" in Dockerfile created by azure-functions-core-tools seems invalid in Azure Functions. #2496

Open yutaro113 opened 3 years ago

yutaro113 commented 3 years ago

Hello Team, I am testing to deploy custom docker image (C# Linux) to Azure Functions and found that path configured in "AzureWebJobsScriptRoot" is not valid in Azure Functions.

Why is this variable configured in the default dockerfile created by this tool even if it's invalid? Should this be removed? Kindly confirm and thank you very much in advance!

Detail : 1, I have created C# Azure function image by following steps. https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-function-linux-custom-image?tabs=bash%2Cportal&pivots=programming-language-csharp

2, In the above procedure, when we use command func init, dockerfile is created with default configuration. Here we can see the environment variable "AzureWebJobsScriptRoot".


FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS installer-env

COPY . /src/dotnet-function-app RUN cd /src/dotnet-function-app && \ mkdir -p /home/site/wwwroot && \ dotnet publish *.csproj --output /home/site/wwwroot

COPY --from=installer-env ["/home/site/wwwroot", "/home/site/wwwroot"]


3, But if we test with different path for publish, no functions are shown in the Portal.


FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS installer-env

COPY . /src/dotnet-function-app RUN cd /src/dotnet-function-app && \ mkdir -p /test && \ dotnet publish *.csproj --output /test


image

4, Based on the discussion below, I could confirm AzureWebJobsScriptRoot is now not valid in Azure Functions (mentioned that application root will always be /home/site/wwwroot). https://github.com/MicrosoftDocs/azure-docs/issues/26761#issuecomment-475908193

apawast commented 3 years ago

@ahmelsayed can you please help investigate this?

yutaro113 commented 3 years ago

@apawast , Thanks for the handling! @ahmelsayed Is there any update on this? Thank you very much!

balag0 commented 3 years ago

@yutaro113

Looks like there are 2 different variations. Either AzureWebJobsScriptRoot or AzureWebsiteHomePath will be used.

https://github.com/Azure/azure-functions-host/blob/c02633967ac893925e7b166a837a2324b8f4c8aa/src/WebJobs.Script/Description/DotNet/FunctionAssemblyLoadContext.cs#L523

In your scenario the functions can't live outside /home/site/wwwroot but it is supported when not running on AppService.