ASP.NET Core Dockerfile无法成为原始路径相对
我们遇到一个非常奇怪的问题,可以为我们的一个API创建一个docker映像,该API在一个由Web API项目引用的单独项目中包含GRPC原型。
这里最明显的区别是,原始文件位于一个单独的项目中。我们还有另一个示例,其中proto文件位于主Web API项目中,并且Dockerfile对该结构运行良好。
此解决方案具有多个项目,并且所有项目都很好,除了一个具有GRPC的项目。 。这是重要的结构:
我们有一个名为“ Eventsengine”的文件夹,其中包含REST API项目,称为“ htlabs.bloxs.blox.eventsapi”,其中包含dockerfile。该项目引用了另一个项目“ htlabs.events.services”,其中包含一个称为库存/proto的子文件夹,其中包含原始文件。
HtECommerce.sln
EventsEngine
HtLabs.Blox.EventsApi
Dockerfile
HtLabs.Events.Services
Inventory
Protos
SimpleInventory.proto
htlabs.events的csproj。服务表明protos像这样正确设置了:
<ItemGroup>
<Protobuf Include="Inventory\Protos\SimpleInventory.proto" GrpcServices="Server,Client" />
<Protobuf Include="Events\Protos\Events.proto" GrpcServices="Server" />
<Protobuf Include="Events\Protos\Tenants.proto" GrpcServices="Server" />
</ItemGroup>
dockerfile非常复杂,因为涉及多个项目,但主要内容如下:
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["*.sln", "./"]
COPY ["EventsEngine/HtLabs.Blox.EventsApi/HtLabs.Blox.EventsApi.csproj", "HtLabs.Blox.EventsApi/"]
COPY ["EventsEngine/HtLabs.Events.Services/HtLabs.Events.Services.csproj", "HtLabs.Events.Services/"]
COPY ["EventsEngine/HtLabs.Blox.EventsApi/nuget.config", ""]
RUN dotnet restore "HtLabs.Blox.EventsApi/HtLabs.Blox.EventsApi.csproj"
COPY . .
WORKDIR "/src/HtLabs.Blox.EventsApi"
RUN dotnet build "HtLabs.Blox.EventsApi.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "HtLabs.Blox.EventsApi.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "HtLabs.Blox.EventsApi.dll"]
我们也知道需要从根部运行dockerfiles (即解决方案所在的文件夹)。对于没有GRPC的其他微服务,这很好。
但是,当我们添加GRPC原型的那一刻,我们会遇到以下错误:
Could not make proto path relative : error : Inventory/Protos/SimpleInventory.proto: No such file or directory [/src/HtLabs.Events.Services/HtLabs.Events.Services.csproj]
一些问题:
- 我们需要还原每个引用项目吗?如在其中,我需要在Dockerfile中包括每个项目吗?
RUN dotnet restore "HtLabs.Events.Services/HtLabs.Events.Services.csproj"
我已经阅读 /a>这可能必须对Dockerfile的创建方式做一些事情。标记的答案显示了一个Dockerfile,但并没有真正确切说明Dockerfile上发生的变化以进行这项工作。有什么想法吗?
我还读过一些有关设置Protoroot的信息,但找不到任何这样做的具体/正确示例。
真的很感谢这里的任何帮助。谢谢你!
We are running into a pretty odd issue in creating a docker image for one of our APIs that contain gRPC protos in a separate project that is referenced by as Web API project.
The most notable difference here is that the proto files reside in a separate project. We have another example where the proto file resides in the the main Web API project and the Dockerfile runs just fine for that structure.
This solution has multiple projects, and all of them work well, except the one that has the gRPC. Here is the structure that matters:
We have a folder called "EventsEngine" that contains the REST API project called "HtLabs.Blox.EventsApi" which contains the Dockerfile. This project references another project "HtLabs.Events.Services" which contains a sub-folder called Inventory/Proto which contains the proto file.
HtECommerce.sln
EventsEngine
HtLabs.Blox.EventsApi
Dockerfile
HtLabs.Events.Services
Inventory
Protos
SimpleInventory.proto
The csproj for the HtLabs.Events.Services shows the protos correctly setup like so:
<ItemGroup>
<Protobuf Include="Inventory\Protos\SimpleInventory.proto" GrpcServices="Server,Client" />
<Protobuf Include="Events\Protos\Events.proto" GrpcServices="Server" />
<Protobuf Include="Events\Protos\Tenants.proto" GrpcServices="Server" />
</ItemGroup>
The Dockerfile is very complex, as there are multiple projects involved, but the main stuff is as follows:
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["*.sln", "./"]
COPY ["EventsEngine/HtLabs.Blox.EventsApi/HtLabs.Blox.EventsApi.csproj", "HtLabs.Blox.EventsApi/"]
COPY ["EventsEngine/HtLabs.Events.Services/HtLabs.Events.Services.csproj", "HtLabs.Events.Services/"]
COPY ["EventsEngine/HtLabs.Blox.EventsApi/nuget.config", ""]
RUN dotnet restore "HtLabs.Blox.EventsApi/HtLabs.Blox.EventsApi.csproj"
COPY . .
WORKDIR "/src/HtLabs.Blox.EventsApi"
RUN dotnet build "HtLabs.Blox.EventsApi.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "HtLabs.Blox.EventsApi.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "HtLabs.Blox.EventsApi.dll"]
We also understand that Dockerfiles need to be run from the root (i.e. the folder where the solution resides). This has worked very well for other microservices that do not have gRPC.
However, the moment we add a gRPC proto, we run into the following error:
Could not make proto path relative : error : Inventory/Protos/SimpleInventory.proto: No such file or directory [/src/HtLabs.Events.Services/HtLabs.Events.Services.csproj]
A few questions:
- Do we need to restore each referenced project? As in, do I need to include each project in the Dockerfile?
RUN dotnet restore "HtLabs.Events.Services/HtLabs.Events.Services.csproj"
I have read elsewhere that this might have to do something with the way the Dockerfile is created. The marked answer shows a Dockerfile but doesn't really state exactly what was changed on the Dockerfile to make this work. Any thoughts?
I have also read something about setting ProtoRoot but couldn't find any concrete/correct examples of doing so.
Would really appreciate any assistance here. Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论