I am stuck and maybe you can help me out. (Update: After investigation, I do know that it is not working because the wwwroot folder for the Azure function after build/release is empty. The main question is why)
I am trying to publish Azure Function using Azure Container Registry (Linux) This step I think I am successful. I did create CI/CD pipeline and everything is being published correctly.
When i enter my azure function main page like: https://myAzureFuncion.azurewebsites.net/ (it is only example)
i do see:
At the begining the function itself. It is nothing fancy, as i just wanted to test the CI/CD so it is the AF template. I just did changed the Auhtorization to Anonymous (to exlude issue with the authentication):
[FunctionName("MyAzureFunctionName")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request. Runned!");
string name = req.Query["name"];
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
name = name ?? data?.name;
return name != null
? (ActionResult)new OkObjectResult($"Hello, {name}")
: new BadRequestObjectResult("Please pass a name on the query string or in the request body");
}
So i good to go - right? No, as it is not working. I am trying to trigget this function by HTTP request:
https://myAzureFuncion.azurewebsites.net/api/MyAzureFunctionName?name=Mark
And I keep getting 404 Not Found. I did check it with Postman: The same (previously with function authorization i did try with ?code=(code_in_host) and with headers x-functions-key. All the time the same info --> 404 Not Found)
It is as this function was not existing.
Of course, when I run it locally (using docker for windows) everything is working correctly. I am running:
https://localhost:some_port/api/MyAzureFunctionName?name=Mark
And I am receiving proper answer.
Can you point me what to check and how to diagnose the issue here? I've entered the App Insights Live Metrics --> but no request is being noted.
How to diagnose the issue here?
[UPDATE 04.05.2020 01:35]
Here is how my release pipeline looks like for this component in YAML
steps:
- task: AzureFunctionAppContainer@1
displayName: 'Azure Function App on Container Deploy: MyFunctionName'
inputs:
azureSubscription: MySubscription
appName: MyFunctionName
imageName: 'myAcrContainer.azurecr.io/mobile/MyFunctionName:$(Build.BuildNumber)'
I saw also one weird thing in Azure Portal for this Azure function. When i go to functions menu - there is information, that there is none:
The same shows up, when i use the "new Azure Function management experience"
[UPDATE 04.05.2020 11:40]
Putting more info on the case. Here is how docker image looks like:
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/azure-functions/dotnet:3.0 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:3.0-buster AS build
WORKDIR /src
COPY ["BuildChat/BuildChat.csproj", "BuildChat/"]
COPY ["MyFunctionName/MyFunctionName.csproj", "MyFunctionName/"]
RUN dotnet restore "MyFunctionName/MyFunctionName.csproj"
COPY . .
WORKDIR "/src/MyFunctionName"
RUN dotnet build "MyFunctionName.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "MyFunctionName.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENV AzureWebJobsScriptRoot=/app
And here is the build pipeline that i am using:
- stage: BuildMyAzureFunction
displayName: Build and push MyAzureFunction stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- task: Docker@2
displayName: Build and push image to container registry
inputs:
containerRegistry: $(dockerRegistryServiceConnection)
repository: $(imageRepositoryMyAzureFunction)
command: 'buildAndPush'
Dockerfile: $(dockerfilePathAzureMyAzureFunction)
tags: |
$(tag)
I do not know what more i can give you :)
Maybe container settings in Azure Portal:
And logs from latest docker release:
2020-05-04 09:32:32.693 INFO - Recycling container because of AppSettingsChange and isMainSite = True
2020-05-04 09:32:32.777 INFO - Pulling image: myAcrContainer.azurecr.io/mobile/myAzureFunction:20200503.11
2020-05-04 09:32:33.829 INFO - 20200503.11 Pulling from mobile/myAzureFunction
2020-05-04 09:32:33.832 INFO - Digest: sha256:688090984dbc5d257b7d4eefff886affa451c59407edd46792dfc81726f393ec
2020-05-04 09:32:33.832 INFO - Status: Image is up to date for myAcrContainer.azurecr.io/mobile/myAzureFunction:20200503.11
2020-05-04 09:32:33.835 INFO - Pull Image successful, Time taken: 0 Minutes and 1 Seconds
2020-05-04 09:32:33.959 INFO - Starting container for site
2020-05-04 09:32:33.961 INFO - docker run -d -p 7287:80 --name myAzureFunction_1_84dd4d10 -e WEBSITE_CORS_ALLOWED_ORIGINS=https://functions.azure.com,https://functions-staging.azure.com,https://functions-next.azure.com -e WEBSITE_CORS_SUPPORT_CREDENTIALS=False -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e WEBSITE_SITE_NAME=myAzureFunction -e WEBSITE_AUTH_ENABLED=False -e PORT=80 -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=myAzureFunction.azurewebsites.net -e WEBSITE_INSTANCE_ID=8da8a02a13a3cdde53ad6aafcd4eb717ca00dd6bc65ff07378d74a0cd859e1c0 -e HTTP_LOGGING_ENABLED=1 myAcrContainer.azurecr.io/mobile/myAzureFunction:20200503.11
2020-05-04 09:32:39.421 INFO - Starting container for site
2020-05-04 09:32:39.422 INFO - docker run -d -p 1500:8081 --name myAzureFunction_1_84dd4d10_middleware -e WEBSITE_CORS_ALLOWED_ORIGINS=https://functions.azure.com,https://functions-staging.azure.com,https://functions-next.azure.com -e WEBSITE_CORS_SUPPORT_CREDENTIALS=False -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e WEBSITE_SITE_NAME=myAzureFunction-e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=myAzureFunction.azurewebsites.net -e WEBSITE_INSTANCE_ID=8da8a02a13a3cdde53ad6aafcd4eb717ca00dd6bc65ff07378d74a0cd859e1c0 -e HTTP_LOGGING_ENABLED=1 appsvc/middleware:2001061754 /Host.ListenUrl=http://0.0.0.0:8081 /Host.DestinationHostUrl=http://172.16.2.6:80 /Host.UseFileLogging=true
2020-05-04 09:32:44.658 INFO - Initiating warmup request to container myAzureFunction_1_84dd4d10 for site myAzureFunction
2020-05-04 09:33:00.400 INFO - Waiting for response to warmup request for container myAzureFunction_1_84dd4d10. Elapsed time = 15.7420671 sec
2020-05-04 09:33:16.088 INFO - Waiting for response to warmup request for container myAzureFunction_1_84dd4d10. Elapsed time = 31.4308809 sec
2020-05-04 09:33:33.284 INFO - Waiting for response to warmup request for container myAzureFunction_1_84dd4d10. Elapsed time = 48.6269148 sec
2020-05-04 09:33:56.001 INFO - Container myAzureFunction_1_84dd4d10 for site myAzureFunctioninitialized successfully and is ready to serve requests.
2020-05-04 09:33:56.004 INFO - Initiating warmup request to container myAzureFunction_1_84dd4d10_middleware for site myAzureFunction
2020-05-04 09:34:04.506 INFO - Container myAzureFunction_1_84dd4d10_middleware for site myAzureFunction initialized successfully and is ready to serve requests.
2020_05_04_RD501AC582A899_easyauth_docker.log:
2020_05_04_RD501AC582A899_default_docker.log:
2020-05-04T09:21:14.187664147Z Hosting environment: Production
2020-05-04T09:21:14.187744046Z Content root path: /app
2020-05-04T09:21:14.187750446Z Now listening on: http://[::]:80
2020-05-04T09:21:14.187754446Z Application started. Press Ctrl+C to shut down.
2020-05-04T09:33:49.229983024Z Hosting environment: Production
2020-05-04T09:33:49.232401696Z Content root path: /app
2020-05-04T09:33:49.232413096Z Now listening on: http://[::]:80
2020-05-04T09:33:49.232417396Z Application started. Press Ctrl+C to shut down.
[UPDATE 04.05.2020 15:55]
I've checked the deployment center, and its look like it is ok:
But because i am publishing 3 thigns (1 SignalR hub and 2 azure functions - of course both "not working") i am thinking - maybe it is getting somehow mixed (and on this azure function app - in fact SignalR is being published?
I did checked this release task log (which suppose to publish MyAzureFunction) and everything looks correctly (everywhere is my MyAzureFunction in the log):
Here is how my Release pipeline looks like:
And here is Continous deployment trigger configuration:
And here is the stage 2 (for publishing azure function) predeployment settings:
And finally, the release step itself (although I did already posted the YAML version of it. To be hones - everything checks out. There is no missmatch in image/app name)
[UPDATE 04.05.2020 16:15]
So right now for 100% i do know what is going on. After successful release without any errors/warnings, the azure function is simply empty :)
I've checked with advanced tools the content of wwwroot (after going to https://myAzureFunction.scm.azurewebsites.net/wwwroot/)
Here is the result:
So it is quite understandable why it is not working :) The main question is "What the hell happened"?:)
I did try in deployment center to Sync the code (as @djsly suggested) but it is not working (probably because it is being managed by containers) But i am adding a message when I try to sync:
[UPDATE 05.05.2020 00:18]
I did connect to Azure container registry and downloaded the image, that suppose to be the image running behing this Azure function in Azure.
So i did runned:
docker login myAcrContainer.azurecr.io
docker pull myAcrContainer.azurecr.io/mobile/myAzureFunction:20200503.11
docker run -it --rm -p 31234:80 myAcrContainer.azurecr.io/mobile/myAzureFunction:20200503.11
and i did hit http://localhost:31234/api/MyAzureFuncionFuns
and everything works correctly. So it confirm my suspisions, that the image is not being properly "runned" on Azure function on Azure portal.
The question is: Am i doing something wrong - or is it an Azure bug?
There was a question regarding my App Service Plan. Here how it looks like (during Azure function creation):
And here are the plan details:
It is a free trial right now (as they proposed it while I was creating it) Could that be the reason? Shouldn't they disallow something instead of allowing and then breaking things ?;)
show source code
? I personally never used AzureDevOps with Azure Function, but for the time I used AzureFuction, the issues I had when it had 0 insight on the Function page was due to a broken/missing source code. – Izabel