From d37e17d912b3505aa5f32e192c40650836dddb3b Mon Sep 17 00:00:00 2001 From: cli <377476583@qq.com> Date: Sun, 27 Apr 2025 11:04:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=B4=E6=97=B6=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 45 +++++++++++++++---- JiShe.CollectBus.sln | 1 + .../appsettings.Production.json | 8 ++++ web/JiShe.CollectBus.Host/appsettings.json | 2 +- 4 files changed, 47 insertions(+), 9 deletions(-) create mode 100644 web/JiShe.CollectBus.Host/appsettings.Production.json diff --git a/Dockerfile b/Dockerfile index edf9081..d4999c8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,25 +22,54 @@ -FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base +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:9.0 AS build +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build WORKDIR /src -COPY . . -WORKDIR "/src/host/JiShe.IOT.HttpApi.Host" -RUN dotnet build "JiShe.IOT.HttpApi.Host.csproj" -c Release -o /app/build +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 "/src/web/JiShe.CollectBus.Host" +RUN dotnet build "JiShe.CollectBus.Host.csproj" -c Release -o /app/build + +# 发布项目 FROM build AS publish -RUN dotnet publish "JiShe.IOT.HttpApi.Host.csproj" -c Release -o /app/publish /p:UseAppHost=false +RUN dotnet publish "JiShe.CollectBus.Host.csproj" -c Release -o /app/publish /p:UseAppHost=false +# 创建最终镜像 FROM base AS final WORKDIR /app -COPY --from=publish /app/publish . -ENTRYPOINT ["dotnet", "JiShe.IOT.HttpApi.Host.dll"] + +# 创建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"] diff --git a/JiShe.CollectBus.sln b/JiShe.CollectBus.sln index 3a0b697..03bd207 100644 --- a/JiShe.CollectBus.sln +++ b/JiShe.CollectBus.sln @@ -62,6 +62,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "0.Docs", "0.Docs", "{D8346C .gitignore = .gitignore Dockerfile = Dockerfile NuGet.Config = NuGet.Config + PackageAndPublish.bat = PackageAndPublish.bat readme.md = readme.md EndProjectSection EndProject diff --git a/web/JiShe.CollectBus.Host/appsettings.Production.json b/web/JiShe.CollectBus.Host/appsettings.Production.json new file mode 100644 index 0000000..bcdd3fc --- /dev/null +++ b/web/JiShe.CollectBus.Host/appsettings.Production.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Warning", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/web/JiShe.CollectBus.Host/appsettings.json b/web/JiShe.CollectBus.Host/appsettings.json index 44180c2..e5fe35d 100644 --- a/web/JiShe.CollectBus.Host/appsettings.json +++ b/web/JiShe.CollectBus.Host/appsettings.json @@ -141,5 +141,5 @@ "DefaultIdempotence": true } }, - "PlugInFolder": "C:\\Users\\Dai Zan\\Desktop\\Plugins" + "PlugInFolder": "" } \ No newline at end of file