I’m trying to deploy an Azure Function (isolated) with .NET 7 to MS Azure using a GitHub Actions workflow. Everything seems to run fine, but for some reason, the Function is not loaded when I deploy it to the cloud. When I run the function local host, everything is fine (works on my machine), once deployed it doesn’t.
public class DemoFunction
{
private readonly ILogger _logger;
public DemoFunction(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<DemoFunction>();
}
[Function("DemoFunction")]
public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req)
{
var response = req.CreateResponse(HttpStatusCode.OK);
response.Headers.Add("Content-Type", "text/plain; charset=utf-8");
response.WriteString("Demo function works!");
return response;
}
}
The Function App contains only a single function with an HTTP binding (no authentication, anonymous requests allowed). I use Bicep to deploy infra and GH Actions to deploy the Function App. Log Analytics shows this:
So for some reason it does find the function, but not load it. If I navigate to the Functions blade in the Azure Portal I don’t see any function. The project is just a POC project and hosted publicly available at https://github.com/nikneem/function-deployment-with-gh-actions
Any ideas?
2
Answers
Oh wow, I found the answer in the deployment process. In my GitHub Actions workflow, I did a
dotnet publish
of the Azure Functions project to an output folder. I zipped the content of the output folder and published that zip file as a workflow artifact.Then in the deployment, I downloaded the workflow artifact (e.g. that zip file) and did a Zip Deployment using that zip file.
Now apparently, something went wrong with this zip file, so I removed that manual zip action, mainly because I found out the deployment step in the GitHub Action also works when you pass a folder containing all published files in.
So the publish step in my GH Actions workflow now looks like this:
and the deployment step looks like this:
Taking a peek at the logs that the deployment process produces, it will still create a zip file and deploy that. But this is a different zip file than I created manually. All works fine now ;)
As per the note in this documentation:
I can see the relevant configuration settings appear to be set correctly in the infrastructure template with the exception of
linuxFxVersion
– this doesn’t seem to be mentioned anywhere and the cicd workflow does appear to be performing a zip deployment.