Azure / azure-functions-dotnet-worker

Azure Functions out-of-process .NET language worker
MIT License
414 stars 181 forks source link

dotnet publish /t:PublishContainer on linux platform does not publish some dlls to a docker image #2641

Open whitebehemoth opened 1 month ago

whitebehemoth commented 1 month ago

Description

If an isolated function is published using PublishContainer target on linux, some DLL are missing in the image.

With WorkerExtensions.csproj included into a solution four of them appears in the image, but not FunctionMetadataLoader. This results LanguageWorkerOptions.WorkerConfigs be empty on container start and have "No job functions found" error on the function start.

Please note, there is no issue with publishing on windows platform.

our workaround for our devops pipeline:

  1. publish without /t:PublishContainer option,
  2. build the image using a simple Dockerfile to copy the published folder,

Steps to reproduce

Issue can be reproduced using sample func on windows with wsl2 Ubuntu 22.04, on dotnet sdk 8.0.303

  1. run func init --worker-runtime dotnet-isolated --docker
  2. run on linux dotnet publish --configuration Release --os linux --arch x64 --property:ContainerRepository=simplefunc --property:ContainerImageTag=linux --target:PublishContainer
  3. run the same command with different tag on windows dotnet publish --configuration Release --os linux --arch x64 --property:ContainerRepository=simplefunc --property:ContainerImageTag=win --target:PublishContainer
  4. compare images docker scout compare --to simplefunc:win simplefunc:linux
  5. check the result: 5 packages are missing (scroll down to see them listed) image
mattchenderson commented 3 weeks ago

I am unable to reproduce this using SDK 8.0.4 / .NET 9 preview 6. For my setup, I am using version 4.0.5907 of the Core Tools, and I ran the commands as presented in the repro steps. This scaffolded the project with Microsoft.Azure.Functions.Worker 1.21.0 and Microsoft.Azure.Functions.Worker.Sdk 1.17.0 as the main dependencies, which I will note are not latest.

I did have a slight issue with the way I did the FS management. I created the files in WSL, then for the Windows run I mounted the WSL FS. When performing that publish, I had a transient error that disappeared with a re-run. This was MSB3030, complaining that the deps.json, dll, runtimeconfig.json, and pdb for my app could not be found. I was able to repeat this after adding a function and trying again, so I think it's something to do with the initial restore. This may be attributable to my setup.

Executing those, though, I get Unhandled exception. System.InvalidOperationException: The gRPC channel URI 'http://:' could not be parsed. for both, which indicates that the worker was started without the host. This makes some sense to me - there is not a base image specified, and I believe the container publish target ignores the dockerfile. From the publish logs (more easily seen with an additional -v d), I can see that it's just using the ASP.NET image for the TFM: Building image 'simplefunc' with tags 'win' on top of base image 'mcr.microsoft.com/dotnet/aspnet:8.0'. I also see (from full diagnostic verbosity) that the output image's AppCommand is `dotnet " which contributes to that. That behavior at least should be addressed when we complete #2617 and set a specific base image and modify the entry point, etc. I believe the stated workaround is the correct approach in the meantime.

@whitebehemoth could you confirm the Core Tools version and how you set up the shared source? Does this still reproduce if you use .NET SDK 8.0.4? I'm also curious about any additional steps taken to get to the "0 functions found" error, as I was unable to get to the point of the host even starting and reporting that.

I had been thinking #2617 should be gated on this issue, but now I'm thinking they could be more related. I'll update that one to reflect that it isn't blocked while we try to understand this one a bit better in parallel. Hopefully it can provide a path forward for this one.

whitebehemoth commented 3 weeks ago

Hey @mattchenderson, thanks for coming back on this. I confirm that I also unable to reproduce this issue with SDK 8.0.401. Which makes me think that the problem was in the SDK. Answering other questions: Core Tools version 4.0.5907 x64, Error "No job functions found" I got on a function app start. App is hosted in k8s cluster, deployed by a pipeline with Lunix agents to a Linux container. Here is a complete step (works now, but did not work with SDK 8.0.303):

- task: DotNetCoreCLI@2
        displayName: Publish build
        inputs:
          command: publish
          projects: |
            $(servicePath)/**/*.csproj
            !$(servicePath)**/obj/**
          arguments: >-
            --configuration Release
            --os linux
            --arch x64
            --no-build
            --target:PublishContainer
            --property:ContainerRepository=$(repositoryName)
            --property:ContainerImageTag=$(Build.BuildId)
          publishWebProjects: false
          zipAfterPublish: false
          modifyOutputPath: false