之前用 dotnet tool 方式被 || true 吞掉错误导致 /ms-playwright 不存在。 改为在 builder 阶段装 Node.js 18 后用 npx playwright@1.44.0 install 下载, 路径可靠,复制到 final 阶段不再报错。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+8
-6
@@ -23,6 +23,12 @@ FROM mcr.microsoft.com/dotnet/sdk:6.0 AS backend-builder
|
|||||||
|
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
|
|
||||||
|
# 安装 Node.js 18(用于 npx playwright install,最可靠的方式)
|
||||||
|
RUN apt-get update && apt-get install -y curl && \
|
||||||
|
curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
|
||||||
|
apt-get install -y nodejs && \
|
||||||
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
COPY *.csproj ./
|
COPY *.csproj ./
|
||||||
RUN dotnet restore dy.net.csproj
|
RUN dotnet restore dy.net.csproj
|
||||||
|
|
||||||
@@ -33,18 +39,15 @@ COPY --from=frontend-builder /app/frontend/dist ./app/dist
|
|||||||
|
|
||||||
RUN dotnet publish dy.net.csproj -c Release -o /app/publish
|
RUN dotnet publish dy.net.csproj -c Release -o /app/publish
|
||||||
|
|
||||||
# 安装 Playwright CLI 并下载 Chromium 浏览器到固定路径
|
# 用 npx 下载 Playwright Chromium 到固定路径
|
||||||
ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
|
ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
|
||||||
RUN dotnet tool install --global Microsoft.Playwright.CLI --version 1.44.0 2>/dev/null || true && \
|
RUN npx -y playwright@1.44.0 install chromium
|
||||||
/root/.dotnet/tools/playwright install chromium --with-deps 2>/dev/null || \
|
|
||||||
dotnet /app/publish/playwright.ps1 install chromium 2>/dev/null || true
|
|
||||||
|
|
||||||
# 第三阶段:运行镜像
|
# 第三阶段:运行镜像
|
||||||
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS final
|
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS final
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# 设置时区
|
|
||||||
ENV TZ=Asia/Shanghai
|
ENV TZ=Asia/Shanghai
|
||||||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||||||
|
|
||||||
@@ -68,7 +71,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|||||||
fonts-liberation \
|
fonts-liberation \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# 从构建阶段复制应用和浏览器
|
|
||||||
COPY --from=backend-builder /app/publish .
|
COPY --from=backend-builder /app/publish .
|
||||||
COPY --from=backend-builder /ms-playwright /ms-playwright
|
COPY --from=backend-builder /ms-playwright /ms-playwright
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user