Files
dysync/Dockerfile.prod
T
yuming d76c1cad87
部署到群晖 / deploy (push) Failing after 5m10s
fix(docker): 改用 npx playwright install 下载 Chromium,确保路径存在
之前用 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>
2026-04-27 09:29:30 +08:00

83 lines
2.1 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 多阶段构建 Dockerfile
# 第一阶段:构建前端
FROM node:18-alpine AS frontend-builder
WORKDIR /app/frontend
COPY app/package.json app/pnpm-lock.yaml* ./
RUN npm config set registry https://registry.npmmirror.com && \
npm install -g pnpm && \
pnpm config set registry https://registry.npmmirror.com && \
if [ -f pnpm-lock.yaml ]; then \
pnpm install --frozen-lockfile; \
else \
npm install; \
fi
COPY app/ ./
RUN pnpm build || npm run build
# 第二阶段:构建后端 + 下载 Playwright Chromium
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS backend-builder
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 ./
RUN dotnet restore dy.net.csproj
COPY . .
RUN find . -name "._*" -type f -delete
COPY --from=frontend-builder /app/frontend/dist ./app/dist
RUN dotnet publish dy.net.csproj -c Release -o /app/publish
# 用 npx 下载 Playwright Chromium 到固定路径
ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
RUN npx -y playwright@1.44.0 install chromium
# 第三阶段:运行镜像
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS final
WORKDIR /app
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# 安装 Chromium 运行时依赖(Debian Bullseye)
RUN apt-get update && apt-get install -y --no-install-recommends \
libnss3 \
libatk1.0-0 \
libatk-bridge2.0-0 \
libcups2 \
libdrm2 \
libxkbcommon0 \
libxcomposite1 \
libxdamage1 \
libxfixes3 \
libxrandr2 \
libgbm1 \
libasound2 \
libpango-1.0-0 \
libpangocairo-1.0-0 \
libgtk-3-0 \
fonts-liberation \
&& rm -rf /var/lib/apt/lists/*
COPY --from=backend-builder /app/publish .
COPY --from=backend-builder /ms-playwright /ms-playwright
ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
EXPOSE 10101
ENV ASPNETCORE_URLS=http://*:10101
ENV ASPNETCORE_ENVIRONMENT=Production
ENTRYPOINT ["dotnet", "dy.net.dll"]