New and learning Dockerfile; need help to edit the following Dockerfile to containerize a C# Azure Function App with Playwright.
Here’s part of the function code:
using System.Net;
using Func_MyFunction.Interfaces;
using Func_MyFunction.Models;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;
using Microsoft.Playwright;
[Function("HttpExample")]
public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req)
{
log.LogInformation("C# HTTP trigger function processed a request.");
var response = req.CreateResponse(HttpStatusCode.OK);
response.Headers.Add("Content-Type", "text/plain; charset=utf-8");
response.WriteString("Welcome to Azure Functions!");
return response;
}
The other endpoints that will checks the UI of an URL and sends an email if it’s not visible.
This is the Dockerfile (with line numbers)
1. FROM mcr.microsoft.com/azure-functions/dotnet-isolated:4-dotnet-isolated6.0 AS base
2. WORKDIR /home/site/wwwroot
3. EXPOSE 80
4.
5. FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
6. ARG BUILD_CONFIGURATION=Release
7. WORKDIR /src
8. COPY . .
9. RUN ls -la
10. RUN dotnet restore "./Func_MyFunction.csproj"
11. RUN dotnet add package Microsoft.Playwright
12. RUN dotnet build "./Func_MyFunction.csproj" -c $BUILD_CONFIGURATION -o /app/build
13. RUN playwright install
14.
15. FROM build AS publish
16. ARG BUILD_CONFIGURATION=Release
17.
18. RUN dotnet publish "./Func_MyFunction.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
19.
20. FROM base AS final
21. WORKDIR /home/site/wwwroot
22. COPY --from=publish /app/publish .
23. ENV AzureWebJobsScriptRoot=/home/site/wwwroot
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
This is the error:
#14 [build 8/8] RUN playwright install
#14 0.415 /bin/sh: 1: playwright: not found
#14 ERROR: process "/bin/sh -c playwright install" did not complete successfully: exit code: 127
------
> [build 8/8] RUN playwright install:
0.415 /bin/sh: 1: playwright: not found
------
Dockerfile:16
--------------------
14 | RUN dotnet add package Microsoft.Playwright
15 | RUN dotnet build "./Func_MyFunction.csproj" -c $BUILD_CONFIGURATION -o /app/build
16 | >>> RUN playwright install
17 |
18 | FROM build AS publish
--------------------
ERROR: failed to solve: process "/bin/sh -c playwright install" did not complete successfully: exit code: 127
2
Answers
There were a couple of errors I had. One was this:
The solution can be found here.
In the .csproj file add:
The other error was:
The root cause was that I was installing playwright in the wrong order of the Dockerfile. It should have been in the 'base' and not 'build'. Also, needed to install playwright dependencies. Here's a working Dockerfile
I am able to install
playwright
using the below docker file.Upon building the docker image, I am getting below output and playwright got installed successfully to the src folder.