Home > Net >  Unable to publish Azure Function to Linux using CLI
Unable to publish Azure Function to Linux using CLI

Time:05-06

I'm currently creating a build pipeline in BitBucket, to move away from our current 'Right Click -> Publish' strategy. I've migrated some of our functions which are hosted on Windows, no problem. We have one function on a Linux app service plan, and unfortunately after publishing it fails to run from the package.

# Publish to a folder
dotnet publish "azure/$FUNCTION_NAME/$FUNCTION_NAME.csproj" -c Release -o publish/$FUNCTION_NAME

# Create a zip file
md artifacts
powershell Compress-Archive publish/$FUNCTION_NAME/** artifacts/$FUNCTION_NAME.zip

# Deploy the zip file to Azure
az functionapp deploy -g $AZURE_RESOURCE_GROUP -n $AZURE_RESOURCE_NAME --src-path artifacts/$FUNCTION_NAME.zip

This is pretty much exactly the steps listed on the Azure Functions documentation page. When publishing to Linux, there are no errors, it just does nothing. In the Azure Portal, all the functions in the app are still listed and the host.json and function.json files seem to be recognized, but I can no longer test/run the function. Every request to the HTTP endpoints returns a 404 status.

I've tried to look through the logs, I'm a bit lost without a UI but I did find these messages:

/home/LogFiles/kudu/deployment/5fd0c28b328b-ec52daf9-7903-466a-bfe1-5c1c658ab72b.txt

::::::::::::::
5fd0c28b328b-ec52daf9-7903-466a-bfe1-5c1c658ab72b.txt
::::::::::::::
2022-05-02T01:41:14  Fetching changes.
2022-05-02T01:41:30  Updating submodules.
2022-05-02T01:41:31  Preparing deployment for commit id '35555aaa-2'.
2022-05-02T01:41:32  Skipping build. Project type: Run-From-Zip
2022-05-02T01:41:32  Skipping post build. Project type: Run-From-Zip
2022-05-02T01:41:32  Requesting site restart
2022-05-02T01:41:33  Requesting site restart. Attempt #1
2022-05-02T01:41:33  Successfully requested a restart. Attempt #1
2022-05-02T01:41:34  Updating /home/data/SitePackages/packagename.txt with deployment 20220502014112.zip
2022-05-02T01:41:35  Deployment successful.
2022-05-02T01:41:38  An unknown error has occurred. Check the diagnostic log for details.

2022-05-02T02-02-31Z-ff1a2fe5e9.log

2022-05-02T02:02:31.309 [Warning] 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.).

Re-publishing from within Visual Studio fixes the problem, so it's definitely an issue with how I am publishing. The publish profile within Visual Studio has a <IsLinux>true</IsLinux> property, which I suspect is what I need to somehow specify for the Azure CLI as well.

CodePudding user response:

I reasoned there must be two possibilities:

  • The method I am using to upload the zip file is not the same as the one used by Visual Studio
  • The zip file I created is not the same as the one produced by Visual Studio

I had a look at the MSBuild tasks in the SDK to see what Visual Studio does when you click publish. From this, I found the zip file is produced by Visual Studio in the obj/Release/net6.0/PubTmp folder. It posts the zip file to https://{FUNCTION}.scm.azurewebsites.net/api/zipdeploy when deploying. I tested this out manually with PostMan, and got the following results:

Deployment method Source Result
POST /api/zipdeploy obj/Release/net6.0/PubTmp Succeeded
POST /api/zipdeploy dotnet publish powershell Compress-Archive Failed
az functionapp deploy obj/Release/net6.0/PubTmp Succeeded
az functionapp deploy dotnet publish powershell Compress-Archive Failed

The table shows that the deployment only fails if I'm using the zip generated from the command line. I used WinMerge to compare the two, but it says they are identical, so I can't tell what is going on. Clearly, there must be some difference between the two zip files, otherwise they would both deploy fine.

I decided I would try and report this as a bug, so I tried to recreate the problem in a new empty project, and straight away had multiple other unrelated issues:

  • In the Azure Portal, when I create a new Function App it won't let me re-use the existing Linux App Service Plan. I have to create it through Visual Studio instead
  • After publishing a new project, with the only function being the default HTTP trigger from the project templates, the deployment failed
  • Consecutive publishes fail because the deployment is still locked
  • The endpoints to browse files in Kudu were throwing an exception, with the stack trace mentioning attempts to use Windows paths

I spent a lot of time investigating this, and came to the conclusion it's not worth trying to host on Linux just yet. That's disappointing, and I hope they get these issues sorted out.

  • Related