用于 C# Azure Function App 的 Dockerfile 与 PlayWright

问题描述 投票:0回答:1

新的和正在学习的 Dockerfile;需要帮助来编辑以下 Dockerfile 以使用 Playwright 容器化 C# Azure Function App。

部分功能代码如下:

using System.Net;
using Func_MonitorAndAlert.Interfaces;
using Func_MonitorAndAlert.Models;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;
using Microsoft.Playwright;

        [Function("SomeFunctionToCall")]
        public async Task<HttpResponseData> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            bool isSomethingDebuggerTraceReportVisible = await validateUi.ValidateSomethingAsync();

            bool isSomethingVisible = await validateUi.ValidateLogiSsmAsync(client);

            if (isSomethingDebuggerTraceReportVisible && isSomethingVisible)
            {
                Console.WriteLine("It is visible");
            }
            else { Console.WriteLine("NOT Visible"); }

            await sendEmail.SendEmailAsync(client);

            string responseMessage = isSomethingDebuggerTraceReportVisible  && isSomethingVisible
                ? "Something IS available"
                : $"Something is NOT available";

            HttpResponseData response = req.CreateResponse(HttpStatusCode.OK);
            await response.WriteAsJsonAsync(responseMessage);

            return response;
        }

还有其他类似的端点可以检查 URL 的 UI,并在不可见时发送电子邮件。

这是 Dockerfile(带有行号)

 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

这是错误:

#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

提前谢谢您!

azure azure-functions dockerfile playwright playwright-dotnet
1个回答
0
投票

我可以使用下面的 docker 文件安装

playwright

FROM mcr.microsoft.com/azure-functions/dotnet-isolated:4-dotnet-isolated6.0 AS base
WORKDIR /home/site/wwwroot
EXPOSE 80

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["FunctionApp63/FunctionApp63.csproj", "FunctionApp63/"]
RUN dotnet restore "./FunctionApp63/FunctionApp63.csproj"
COPY . .
WORKDIR "/src/FunctionApp63"
RUN dotnet build "./FunctionApp63.csproj" -c $BUILD_CONFIGURATION -o /app/build

# Install Playwright
RUN apt-get update && \
    apt-get install -y curl && \
    curl -fsSL https://deb.nodesource.com/setup_16.x | bash - && \
    apt-get install -y nodejs
RUN npm install -g playwright
RUN playwright install

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./FunctionApp63.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /home/site/wwwroot
COPY --from=publish /app/publish .
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
    AzureFunctionsJobHost__Logging__Console__IsEnabled=true

构建 docker 映像后,我得到以下输出,并且 playwright 已成功安装到 src 文件夹。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.