Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grpc.Tools generation doesn't work on Alpine Linux (incompatible protoc & grpc_csharp_plugin binaries). #24188

Closed
Sshnyari opened this issue Sep 18, 2020 · 8 comments

Comments

@Sshnyari
Copy link

What version of gRPC and what language are you using?

grpc.tools 2.31.0

What operating system (Linux, Windows,...) and version?

Alpine 3.12 (more precisely the mcr.microsoft.com/dotnet/core/sdk:3.1-alpine image)

What runtime / compiler are you using (e.g. python version or version of gcc)

netcoreapp 3.1

What did you do?

When building a dotnet app docker image based on alpine, I got the error reported in #18338. I tried the workaround specified in the issue but changed the grpc.tools version to 2.31.0 (because that is the one shipped with the nuget package), but I got the error mentioned below.

What did you expect to see?

The image to build.

What did you see instead?

The image fails to build with the following error

Error relocating /root/.nuget/packages/grpc.tools/2.31.0/tools/linux_x64/grpc_csharp_plugin : error : __strftime_l: symbol not found [/project-path/project-name.csproj]
--grpc_out : error : protoc-gen-grpc: Plugin failed with status code 127. [/project-path/project-name.csproj]
The command '/bin/sh -c dotnet publish "project-name.csproj" -c Release -o /app/publish' returned a non-zero code: 1

Anything else we should know about your project / environment?

The only changes from the issue #18338 and this one are the versions :

  • netcoreapp 3.1 instead of netcoreapp2.2
  • grpc.tools 2.31.0 instead of 1.19.0

Either I missed something or the workaround no longer works. If it is the latter, the closing comment of #18338 does not apply anymore. Will there be plans to support alpine if this is the case ?

@dbettin
Copy link

dbettin commented Apr 11, 2021

I am running into the same issue w/ the following versions:

  • netcoreapp 5.0
  • grpc.tools 2.34.0

@jtattermusch Any updates (or do you need more info)? Currently using the latest dotnet GRPC is not possible on alpine.

@sandord
Copy link

sandord commented Apr 14, 2021

Same here with Grpc.Tools 2.37.0.

#15 22.52 /root/.nuget/packages/grpc.tools/2.37.0/build/_protobuf/Google.Protobuf.Tools.targets(280,5): error MSB6003: The specified task executable "/root/.nuget/packages/grpc.tools/2.37.0/tools/linux_x64/protoc" could not be run. System.ComponentModel.Win32Exception (2): No such file or directory [/app/src/XX/XX.csproj]
#15 22.52 /root/.nuget/packages/grpc.tools/2.37.0/build/_protobuf/Google.Protobuf.Tools.targets(280,5): error MSB6003:    at System.Diagnostics.Process.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec) [/app/src/XX/XX.csproj]
#15 22.52 /root/.nuget/packages/grpc.tools/2.37.0/build/_protobuf/Google.Protobuf.Tools.targets(280,5): error MSB6003:    at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo) [/app/src/XX/XX.csproj]
#15 22.52 /root/.nuget/packages/grpc.tools/2.37.0/build/_protobuf/Google.Protobuf.Tools.targets(280,5): error MSB6003:    at System.Diagnostics.Process.Start() [/app/src/XX/XX.csproj]
#15 22.52 /root/.nuget/packages/grpc.tools/2.37.0/build/_protobuf/Google.Protobuf.Tools.targets(280,5): error MSB6003:    at Microsoft.Build.Utilities.ToolTask.ExecuteTool(String pathToTool, String responseFileCommands, String commandLineCommands) [/app/src/XX/XX.csproj]
#15 22.52 /root/.nuget/packages/grpc.tools/2.37.0/build/_protobuf/Google.Protobuf.Tools.targets(280,5): error MSB6003:    at Microsoft.Build.Utilities.ToolTask.Execute() [/app/src/XX/XX.csproj]

@mtarcha
Copy link

mtarcha commented Apr 26, 2021

I fixed this in my project by replacing usage of image mcr.microsoft.com/dotnet/sdk:5.0-alpine for mcr.microsoft.com/dotnet/sdk:5.0

@sandord
Copy link

sandord commented Apr 26, 2021

I fixed this in my project by replacing usage of image mcr.microsoft.com/dotnet/sdk:5.0-alpine for mcr.microsoft.com/dotnet/sdk:5.0

The downside of that approach is that you can't use self-contained deployments since it forces you to specify the platform, which in turn must match the platform of the sdk the project was built with.

In other words: the flavor of the build base image (e.g. sdk:5.0-alpine) must match the flavor of the runtime image (e.g. runtime-deps:5.0-alpine) for self-contained deployments.

Besides, the whole point (at least for me) to use Alpine, is to reduce the size of the resulting image.

@seanamos
Copy link

There was originally a workaround for this using: https://github.com/sgerrand/alpine-pkg-glibc
You have to use v2.34-r0, not the latest version which has its own problems.

That still seems to get the csharp grpc plugin working on alpine linux/amd64.
There is currently no off the shelf workaround for alpine linux/arm64. Some people have been doing their own builds of https://github.com/sgerrand/alpine-pkg-glibc for arm64.

@tonydnewell
Copy link
Contributor

As a workaround - once #27099 is released (it has been merged) you will be able to use the GRPC_PROTOC_PLUGIN environment variable to point to your own plugin that is built to work on alpine.

@jtattermusch jtattermusch changed the title Grpc.Tools generation doesn't work in alpine Grpc.Tools generation doesn't work on Alpine Linux (incompatible protoc & grpc_csharp_plugin binaries). Oct 11, 2022
@tonydnewell
Copy link
Contributor

tonydnewell commented Jan 25, 2023

Summary of current workaround for anyone coming across this issue:

The binaries shipped in Grpc.Tools currently do not work on alpine linux. However there are binaries that do work and these can be downloaded from: https://pkgs.alpinelinux.org/package/edge/community/x86_64/grpc-plugins

So a workaround to use Grpc.Tools on alpine:

# install grpc-plugins package to get tools built for Alpine linux
apk add grpc-plugins

# set environment variables for the tools
export PROTOBUF_PROTOC=/usr/bin/protoc
export GRPC_PROTOC_PLUGIN=/usr/bin/grpc_csharp_plugin

# do the .NET build
dotnet build

Note: You need Grpc.Tools version 2.50.0 or later for this workaround to work.

@tonydnewell
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants