buildpacks icon indicating copy to clipboard operation
buildpacks copied to clipboard

Could not build C# sample image for gRPC due to project layout

Open ahmetb opened this issue 4 years ago • 5 comments

I am trying to build gRPC RouteGuide example project. https://github.com/grpc/grpc/tree/cc03415b78f8d562ccd9d7100c408fc65c013783/examples/csharp/RouteGuide

It has a tree structure as follows:

..
├── README.md
├── RouteGuide
│   ├── RouteGuide.csproj
│   ├── RouteGuideUtil.cs
│   └── route_guide_db.json
├── RouteGuide.sln
├── RouteGuideClient
│   ├── Program.cs
│   └── RouteGuideClient.csproj
└── RouteGuideServer              <--- want to containerize this
    ├── Program.cs
    ├── RouteGuideImpl.cs
    └── RouteGuideServer.csproj

3 directories, 10 files

RouteGuideServer what I'm interested in building.

However, its *.csproj file refers to ..\RouteGuide\RouteGuide.csproj.

If I run pack build in . of this tree, it thinks it's ambiguous:

[builder] Failure: (ID: 091c027c) expected to find exactly one project file in directory ., found [./RouteGuide/RouteGuide.csproj ./RouteGuideServer/RouteGuideServer.csproj ./RouteGuideClient/RouteGuideClient.csproj]

If I run pack build in ./RouteGuideServer, it probably doesn't add .. to the docker-build context, so it can't find the imported ..*.csproj:

[builder] /layers/google.dotnet.runtime/sdk/3.1.404/Microsoft.Common.CurrentVersion.targets(1850,5): warning : The referenced project '../RouteGuide/RouteGuide.csproj' does not exist. [/workspace/RouteGuideServer.csproj]

I am no C# expert but I think this layout (.csproj files referring to one another within a .sln) is faily standard in C# ecosystem. However, it seems we can't support it properly.

ahmetb avatar Nov 10 '20 19:11 ahmetb

pack, similarly to docker will only include the files in the current directory (or the directory specified by --path) in the build context. The project you link is structured in a way that requires the whole example directory to be accessible (examples/protos is pulled in somewhere). I was able to build the app with:

pack build app -e GOOGLE_BUILDABLE=csharp/RouteGuide/RouteGuideServer

run from inside the grpc/examples directory.

It failed to run because it requires .NET Core 2.1 and hardcodes the port.

After modifying:

  • csharp/RouteGuide/RouteGuideServer/Program.cs to set port to 8080
  • csharp/RouteGuide/RouteGuideServer/RouteGuideServer.csproj to specify netcoreapp3.1

I got the app to both build and run. However, I'm not quite sure what it's supposed to do so I didn't explore farther than that and am not sure if it actually works.

Side note: We should probably document GOOGLE_BUILDABLE in the failure message you saw to make these steps more obvious.

lukasberger avatar Nov 10 '20 20:11 lukasberger

Thanks for swift answer. Agreed, if GOOGLE_BUILDABLE was documented under .NET section in the README, I'd use it right away, my eyes looked for it.

ahmetb avatar Nov 10 '20 20:11 ahmetb

It's applicable to Go as well, so it's under the Common Options section: https://github.com/GoogleCloudPlatform/buildpacks#common-options. By the .NET section do mean the under "default entrypoint behavior"?

lukasberger avatar Nov 10 '20 20:11 lukasberger

I expected it under Language-idiomatic configuration options section. I didn't see #common-options while scrolling at all. :)

ahmetb avatar Nov 10 '20 20:11 ahmetb

Specifically at https://github.com/GoogleCloudPlatform/buildpacks/tree/d383a144ccb298a9202f4cd2ee5f8b83440d4985#language-idiomatic-configuration-options

ahmetb avatar Nov 10 '20 21:11 ahmetb