Skip to content

Commit

Permalink
升级基础镜像版本并添加容器调试支持
Browse files Browse the repository at this point in the history
更新了基础镜像版本,从 `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` 文件的内容项。
  • Loading branch information
239573049 committed Nov 13, 2024
1 parent 4fc96a6 commit 85c4bd6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 20 deletions.
36 changes: 22 additions & 14 deletions src/Thor.Service/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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/"]
Expand All @@ -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"]
10 changes: 10 additions & 0 deletions src/Thor.Service/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 3 additions & 6 deletions src/Thor.Service/Thor.Service.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
<ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>..\..</DockerfileContext>
<RuntimeIdentifiers>linux-x64</RuntimeIdentifiers>
<EnableSdkContainerDebugging>True</EnableSdkContainerDebugging>
<ContainerBaseImage>mcr.microsoft.com/dotnet/aspnet:9.0</ContainerBaseImage>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -65,10 +68,4 @@
<Folder Include="wwwroot\" />
</ItemGroup>

<ItemGroup>
<Content Include="..\..\.dockerignore">
<Link>.dockerignore</Link>
</Content>
</ItemGroup>

</Project>

0 comments on commit 85c4bd6

Please sign in to comment.