Files
dysync/Dockerfile.prod
T
yuming 2a4ce563b0
部署到群晖 / deploy (push) Failing after 1m27s
fix: 改用 Playwright Headless Chromium 实现扫码登录
sso.douyin.com 有 JS 反爬,纯 HTTP 无法通过。
改用 Microsoft.Playwright 驱动 Headless Chromium 打开
creator.douyin.com 登录页,直接提取 QR 码 base64 和登录后 Cookie。

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-27 09:22:15 +08:00

81 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
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
# 安装 Playwright CLI 并下载 Chromium 浏览器到固定路径
ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
RUN dotnet tool install --global Microsoft.Playwright.CLI --version 1.44.0 2>/dev/null || true && \
/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
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"]