- Add `.drone.yml` with Drone CI pipeline for automated Docker image building and deployment - Configure multi-stage build process: build Docker images and push to Harbor registry, then deploy via SSH - Add CI-CD deployment documentation with architecture overview, quick start guide, and configuration templates - Include single-service and multi-service project templates for reference - Update `src/Dockerfile` for CI/CD integration - Enable automated deployment to staging server on master branch push events
91 lines
2.4 KiB
Docker
91 lines
2.4 KiB
Docker
# 构建阶段
|
|
FROM 192.168.195.25:19900/library/dotnet/sdk:9.0 AS build
|
|
WORKDIR /src
|
|
|
|
# 复制项目文件
|
|
COPY HtmlToPdfService.sln .
|
|
COPY HtmlToPdfService.Api/HtmlToPdfService.Api.csproj HtmlToPdfService.Api/
|
|
COPY HtmlToPdfService.Core/HtmlToPdfService.Core.csproj HtmlToPdfService.Core/
|
|
COPY HtmlToPdfService.Queue/HtmlToPdfService.Queue.csproj HtmlToPdfService.Queue/
|
|
COPY HtmlToPdfService.Infrastructure/HtmlToPdfService.Infrastructure.csproj HtmlToPdfService.Infrastructure/
|
|
COPY HtmlToPdfService.Client/HtmlToPdfService.Client.csproj HtmlToPdfService.Client/
|
|
COPY HtmlToPdfService.Tests/HtmlToPdfService.Tests.csproj HtmlToPdfService.Tests/
|
|
|
|
# 还原 NuGet 包
|
|
RUN dotnet restore HtmlToPdfService.sln
|
|
|
|
# 复制所有源代码
|
|
COPY . .
|
|
|
|
# 构建
|
|
RUN dotnet build HtmlToPdfService.sln -c Release --no-restore
|
|
|
|
# 发布
|
|
RUN dotnet publish HtmlToPdfService.Api/HtmlToPdfService.Api.csproj -c Release -o /app/publish --no-build
|
|
|
|
# 运行时阶段
|
|
FROM 192.168.195.25:19900/library/dotnet/aspnet:9.0 AS runtime
|
|
|
|
# 安装 Chromium 依赖
|
|
RUN apt-get update && apt-get install -y \
|
|
# Chromium 依赖
|
|
libnss3 \
|
|
libnspr4 \
|
|
libatk1.0-0 \
|
|
libatk-bridge2.0-0 \
|
|
libcups2 \
|
|
libdrm2 \
|
|
libdbus-1-3 \
|
|
libxkbcommon0 \
|
|
libx11-6 \
|
|
libxcomposite1 \
|
|
libxdamage1 \
|
|
libxext6 \
|
|
libxfixes3 \
|
|
libxrandr2 \
|
|
libgbm1 \
|
|
libpango-1.0-0 \
|
|
libcairo2 \
|
|
libasound2 \
|
|
libatspi2.0-0 \
|
|
# 字体支持
|
|
fonts-liberation \
|
|
fonts-noto-cjk \
|
|
fonts-noto-cjk-extra \
|
|
fonts-noto-color-emoji \
|
|
fonts-dejavu-core \
|
|
fonts-freefont-ttf \
|
|
fontconfig \
|
|
# 工具
|
|
wget \
|
|
ca-certificates \
|
|
&& apt-get clean \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# 创建应用目录
|
|
WORKDIR /app
|
|
|
|
# 复制发布文件
|
|
COPY --from=build /app/publish .
|
|
|
|
# 创建存储目录
|
|
RUN mkdir -p /app/files /app/logs /app/config /app/chromium && chmod -R 777 /app/files /app/logs /app/config /app/chromium
|
|
|
|
# 设置环境变量
|
|
ENV ASPNETCORE_URLS=http://+:5000
|
|
ENV ASPNETCORE_ENVIRONMENT=Production
|
|
ENV DOTNET_RUNNING_IN_CONTAINER=true
|
|
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=false
|
|
ENV PUPPETEER_CACHE_DIR=/app/chromium
|
|
|
|
# 暴露端口
|
|
EXPOSE 5000
|
|
|
|
# 健康检查
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
|
CMD wget --quiet --tries=1 --spider http://localhost:5000/health || exit 1
|
|
|
|
# 启动应用
|
|
ENTRYPOINT ["dotnet", "HtmlToPdfService.Api.dll"]
|
|
|