From 85c4bd685ca46131cac5161804ebd9e1e60a7465 Mon Sep 17 00:00:00 2001 From: token <239573049@qq.com> Date: Wed, 13 Nov 2024 11:11:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E5=9F=BA=E7=A1=80=E9=95=9C?= =?UTF-8?q?=E5=83=8F=E7=89=88=E6=9C=AC=E5=B9=B6=E6=B7=BB=E5=8A=A0=E5=AE=B9?= =?UTF-8?q?=E5=99=A8=E8=B0=83=E8=AF=95=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新了基础镜像版本,从 `mcr.microsoft.com/dotnet/aspnet:8.0` 升级到 `mcr.microsoft.com/dotnet/aspnet:9.0`。 在 Dockerfile 中添加了中文注释,解释了各个阶段的用途。 将 `EXPOSE` 端口从 `8081` 移除。 在 `build` 阶段中,更新了 .NET SDK 版本,从 `mcr.microsoft.com/dotnet/sdk:8.0` 升级到 `mcr.microsoft.com/dotnet/sdk:9.0`。 调整了项目文件的复制顺序,重新添加了一些项目文件的复制命令。 更新了 `dotnet restore` 和 `dotnet build` 命令的路径。 在 `launchSettings.json` 中添加了新的启动配置 `Container (.NET SDK)`,用于容器调试。 在 `Thor.Service.csproj` 中添加了 `RuntimeIdentifiers`、`EnableSdkContainerDebugging` 和 `ContainerBaseImage` 属性,以支持容器调试。 移除了 `Thor.Service.csproj` 中的 `.dockerignore` 文件的内容项。 --- src/Thor.Service/Dockerfile | 36 +++++++++++-------- .../Properties/launchSettings.json | 10 ++++++ src/Thor.Service/Thor.Service.csproj | 9 ++--- 3 files changed, 35 insertions(+), 20 deletions(-) diff --git a/src/Thor.Service/Dockerfile b/src/Thor.Service/Dockerfile index e031fda..d17ef58 100644 --- a/src/Thor.Service/Dockerfile +++ b/src/Thor.Service/Dockerfile @@ -1,10 +1,12 @@ -FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base +# 请参阅 https://aka.ms/customizecontainer 以了解如何自定义调试容器,以及 Visual Studio 如何使用此 Dockerfile 生成映像以更快地进行调试。 + +# 此阶段用于在快速模式(默认为调试配置)下从 VS 运行时 +FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base USER root RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime RUN echo "Asia/Shanghai" > /etc/timezone WORKDIR /app EXPOSE 8080 -EXPOSE 8081 FROM node as lobe WORKDIR /src @@ -13,9 +15,12 @@ RUN yarn RUN npm i RUN yarn run build -FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build + +# 此阶段用于生成服务项目 +FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build ARG BUILD_CONFIGURATION=Release WORKDIR /src +COPY ["Directory.Build.props", "."] COPY ["src/Thor.Service/Thor.Service.csproj", "src/Thor.Service/"] COPY ["src/extensions/Thor.AzureOpenAI/Thor.AzureOpenAI.csproj", "src/extensions/Thor.AzureOpenAI/"] COPY ["src/Thor.Abstractions/Thor.Abstractions.csproj", "src/Thor.Abstractions/"] @@ -32,30 +37,33 @@ COPY ["src/extensions/Thor.Qiansail/Thor.Qiansail.csproj", "src/extensions/Thor. COPY ["src/extensions/Thor.SparkDesk/Thor.SparkDesk.csproj", "src/extensions/Thor.SparkDesk/"] COPY ["src/framework/Thor.BuildingBlocks.Cache/Thor.BuildingBlocks.Cache.csproj", "src/framework/Thor.BuildingBlocks.Cache/"] COPY ["src/framework/Thor.BuildingBlocks.Event/Thor.BuildingBlocks.Event.csproj", "src/framework/Thor.BuildingBlocks.Event/"] -COPY ["src/Provider/Thor.Provider.DM/Thor.Provider.DM.csproj", "src/Provider/Thor.Provider.DM/"] -COPY ["src/Thor.Infrastructure/Thor.Infrastructure.csproj", "src/Thor.Infrastructure/"] -COPY ["src/Thor.Domain/Thor.Domain.csproj", "src/Thor.Domain/"] -COPY ["src/Thor.Core/Thor.Core.csproj", "src/Thor.Core/"] COPY ["src/framework/Thor.LocalEvent/Thor.LocalEvent.csproj", "src/framework/Thor.LocalEvent/"] COPY ["src/framework/Thor.LocalMemory.Cache/Thor.LocalMemory.Cache.csproj", "src/framework/Thor.LocalMemory.Cache/"] COPY ["src/framework/Thor.RabbitMQEvent/Thor.RabbitMQEvent.csproj", "src/framework/Thor.RabbitMQEvent/"] +COPY ["src/framework/Thor.Stack.Rabbit/Thor.Rabbit.csproj", "src/framework/Thor.Stack.Rabbit/"] COPY ["src/framework/Thor.RedisMemory.Cache/Thor.RedisMemory.Cache.csproj", "src/framework/Thor.RedisMemory.Cache/"] -COPY ["src/Thor.ServiceDefaults/Thor.ServiceDefaults.csproj", "src/Thor.ServiceDefaults/"] -COPY ["src/Provider/Thor.Provider.Sqlite/Thor.Provider.Sqlite.csproj", "src/Provider/Thor.Provider.Sqlite/"] -COPY ["src/Provider/Thor.Provider.PostgreSQL/Thor.Provider.PostgreSQL.csproj", "src/Provider/Thor.Provider.PostgreSQL/"] +COPY ["src/Provider/Thor.Provider.DM/Thor.Provider.DM.csproj", "src/Provider/Thor.Provider.DM/"] +COPY ["src/Thor.Core/Thor.Core.csproj", "src/Thor.Core/"] +COPY ["src/Thor.Domain/Thor.Domain.csproj", "src/Thor.Domain/"] +COPY ["src/Thor.Infrastructure/Thor.Infrastructure.csproj", "src/Thor.Infrastructure/"] COPY ["src/Provider/Thor.Provider.MySql/Thor.Provider.MySql.csproj", "src/Provider/Thor.Provider.MySql/"] +COPY ["src/Provider/Thor.Provider.PostgreSQL/Thor.Provider.PostgreSQL.csproj", "src/Provider/Thor.Provider.PostgreSQL/"] +COPY ["src/Provider/Thor.Provider.Sqlite/Thor.Provider.Sqlite.csproj", "src/Provider/Thor.Provider.Sqlite/"] COPY ["src/Provider/Thor.Provider.SqlServer/Thor.Provider.SqlServer.csproj", "src/Provider/Thor.Provider.SqlServer/"] -RUN dotnet restore "src/Thor.Service/Thor.Service.csproj" +COPY ["src/Thor.ServiceDefaults/Thor.ServiceDefaults.csproj", "src/Thor.ServiceDefaults/"] +RUN dotnet restore "./src/Thor.Service/Thor.Service.csproj" COPY . . WORKDIR "/src/src/Thor.Service" -RUN dotnet build "Thor.Service.csproj" -c $BUILD_CONFIGURATION -o /app/build +RUN dotnet build "./Thor.Service.csproj" -c $BUILD_CONFIGURATION -o /app/build +# 此阶段用于发布要复制到最终阶段的服务项目 FROM build AS publish ARG BUILD_CONFIGURATION=Release -RUN dotnet publish "Thor.Service.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false +RUN dotnet publish "./Thor.Service.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false +# 此阶段在生产中使用,或在常规模式下从 VS 运行时使用(在不使用调试配置时为默认值) FROM base AS final WORKDIR /app COPY --from=publish /app/publish . COPY --from=lobe /src/dist ./wwwroot -ENTRYPOINT ["dotnet", "Thor.Service.dll"] +ENTRYPOINT ["dotnet", "Thor.Service.dll"] \ No newline at end of file diff --git a/src/Thor.Service/Properties/launchSettings.json b/src/Thor.Service/Properties/launchSettings.json index 20a4bf5..8127823 100644 --- a/src/Thor.Service/Properties/launchSettings.json +++ b/src/Thor.Service/Properties/launchSettings.json @@ -42,6 +42,16 @@ "OTEL_SERVICE_NAME": "Thor.Service" }, "distributionName": "" + }, + "Container (.NET SDK)": { + "commandName": "SdkContainer", + "launchBrowser": true, + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger", + "environmentVariables": { + "ASPNETCORE_HTTP_PORTS": "8080" + }, + "publishAllPorts": true, + "useSSL": false } }, "$schema": "http://json.schemastore.org/launchsettings.json", diff --git a/src/Thor.Service/Thor.Service.csproj b/src/Thor.Service/Thor.Service.csproj index 6330fdc..aeb44cc 100644 --- a/src/Thor.Service/Thor.Service.csproj +++ b/src/Thor.Service/Thor.Service.csproj @@ -6,6 +6,9 @@ enable Linux ..\.. + linux-x64 + True + mcr.microsoft.com/dotnet/aspnet:9.0 @@ -65,10 +68,4 @@ - - - .dockerignore - - -