FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
ENV TZ=Asia/Shanghai
ENV ASPNETCORE_ENVIRONMENT=Production

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
# WORKDIR /src
COPY ["JiShe.CollectBus.sln", "."]
COPY ["common.props", "."]
COPY ["NuGet.Config", "."]
COPY ["web/", "web/"]
COPY ["modules/", "modules/"]
COPY ["services/", "services/"]
COPY ["shared/", "shared/"]
COPY ["protocols/", "protocols/"]

# 恢复项目依赖
RUN dotnet restore "JiShe.CollectBus.sln"

# 构建项目
WORKDIR "/web/JiShe.CollectBus.Host"
RUN dotnet build "JiShe.CollectBus.Host.csproj" -c Release -o /app/build

# 发布项目
FROM build AS publish
RUN dotnet publish "JiShe.CollectBus.Host.csproj" -c Release -o /app/publish /p:UseAppHost=false

# 创建最终镜像
FROM base AS final

WORKDIR /app

# 创建Plugins目录
RUN mkdir -p /app/Plugins

# 复制发布内容
COPY --from=publish /app/publish .

# 健康检查
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
  CMD curl -f http://localhost:80/health || exit 1

# 设置入口点
ENTRYPOINT ["dotnet", "JiShe.CollectBus.Host.dll"]

# 启动命令
# 可选：添加命令行参数
# CMD ["--urls", "http://+:80"]


