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

Not working in .NET Core docker image #252

Closed
labsilva opened this issue Nov 13, 2018 · 6 comments
Closed

Not working in .NET Core docker image #252

labsilva opened this issue Nov 13, 2018 · 6 comments
Labels

Comments

@labsilva
Copy link

labsilva commented Nov 13, 2018

Hello!

Just added NerdBank.GitVersioning to a .NET Core solution, and I'm receiving some errors.
The solution is build with GitLab CI on a Docker container running the image microsoft/dotnet:2.1-sdk.
The error I'm getting when building:

/root/.nuget/packages/nerdbank.gitversioning/2.2.33/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018: The "Nerdbank.GitVersioning.Tasks.GetBuildVersion" task failed unexpectedly. [/build/nerdbank.csproj]
/root/.nuget/packages/nerdbank.gitversioning/2.2.33/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018: System.TypeInitializationException: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. ---> System.DllNotFoundException: Unable to load shared library '/root/.nuget/packages/nerdbank.gitversioning/2.2.33/build/lib/linux/x86_64/libgit2-6311e88.so' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libssl.so.1.0.0: cannot open shared object file: No such file or directory [/build/nerdbank.csproj]
/root/.nuget/packages/nerdbank.gitversioning/2.2.33/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018:    at System.Runtime.Loader.AssemblyLoadContext.InternalLoadUnmanagedDllFromPath(String unmanagedDllPath) [/build/nerdbank.csproj]
/root/.nuget/packages/nerdbank.gitversioning/2.2.33/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018:    at System.Runtime.Loader.AssemblyLoadContext.LoadUnmanagedDllFromPath(String unmanagedDllPath) [/build/nerdbank.csproj]
/root/.nuget/packages/nerdbank.gitversioning/2.2.33/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018:    at MSBuildExtensionTask.ContextAwareTask.CustomAssemblyLoader.LoadUnmanagedDll(String unmanagedDllName) [/build/nerdbank.csproj]
/root/.nuget/packages/nerdbank.gitversioning/2.2.33/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018:    at System.Runtime.Loader.AssemblyLoadContext.ResolveUnmanagedDll(String unmanagedDllName, IntPtr gchManagedAssemblyLoadContext) [/build/nerdbank.csproj]
/root/.nuget/packages/nerdbank.gitversioning/2.2.33/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018:    at LibGit2Sharp.Core.NativeMethods.git_libgit2_init() [/build/nerdbank.csproj]
/root/.nuget/packages/nerdbank.gitversioning/2.2.33/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018:    at LibGit2Sharp.Core.NativeMethods.LoadNativeLibrary() [/build/nerdbank.csproj]
/root/.nuget/packages/nerdbank.gitversioning/2.2.33/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018:    at LibGit2Sharp.Core.NativeMethods..cctor() [/build/nerdbank.csproj]
/root/.nuget/packages/nerdbank.gitversioning/2.2.33/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018:    --- End of inner exception stack trace --- [/build/nerdbank.csproj]
/root/.nuget/packages/nerdbank.gitversioning/2.2.33/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018:    at LibGit2Sharp.Core.NativeMethods.git_libgit2_opts(Int32 option, UInt32 level, String path) [/build/nerdbank.csproj]
/root/.nuget/packages/nerdbank.gitversioning/2.2.33/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018:    at LibGit2Sharp.GlobalSettings.SetConfigSearchPaths(ConfigurationLevel level, String[] paths) [/build/nerdbank.csproj]
/root/.nuget/packages/nerdbank.gitversioning/2.2.33/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018:    at Nerdbank.GitVersioning.GitExtensions.OpenGitRepo(String pathUnderGitRepo) [/build/nerdbank.csproj]
/root/.nuget/packages/nerdbank.gitversioning/2.2.33/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018:    at Nerdbank.GitVersioning.VersionOracle.Create(String projectDirectory, String gitRepoDirectory, ICloudBuild cloudBuild, Nullable`1 overrideBuildNumberOffset, String projectPathRelativeToGitRepoRoot) [/build/nerdbank.csproj]
/root/.nuget/packages/nerdbank.gitversioning/2.2.33/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018:    at Nerdbank.GitVersioning.Tasks.GetBuildVersion.ExecuteInner() [/build/nerdbank.csproj]

After digging around for a couple of hours, I tried to create a new console project inside the container and then adding NerdBank.GitVersioning:

Running in Docker docker run --rm -it microsoft/dotnet:2.1-sdk bash

apt-get update -y && apt-get upgrade -y
export PATH="$PATH:/root/.dotnet/tools"
dotnet tool install -g nbgv
git init
dotnet new console
nbgv install

And then I got the following error:

Unhandled Exception: System.TypeInitializationException: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. ---> System.DllNotFoundException: Unable to load shared library 'git2-6311e88' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libgit2-6311e88: cannot open shared object file: No such file or directory
   at LibGit2Sharp.Core.NativeMethods.git_libgit2_init()
   at LibGit2Sharp.Core.NativeMethods.LoadNativeLibrary()
   at LibGit2Sharp.Core.NativeMethods..cctor()
   --- End of inner exception stack trace ---
   at LibGit2Sharp.Core.NativeMethods.git_libgit2_opts(Int32 option, UInt32 level, String path)
   at LibGit2Sharp.GlobalSettings.SetConfigSearchPaths(ConfigurationLevel level, String[] paths)
   at Nerdbank.GitVersioning.GitExtensions.OpenGitRepo(String pathUnderGitRepo)
   at Nerdbank.GitVersioning.Tool.Program.OnInstallCommand(String versionJsonRoot, String version) in D:\a\1\s\src\nbgv\Program.cs:line 151
   at Nerdbank.GitVersioning.Tool.Program.Main(String[] args) in D:\a\1\s\src\nbgv\Program.cs:line 100

I've googled a bit and found some issues similar to mine, but the workarounds or solutions provided didn't work.

Am I doing anything wrong? Can someone point in the right direction?

@AArnott
Copy link
Collaborator

AArnott commented Nov 14, 2018

Hi @labsilva, thanks for reaching out. I think the discussion in #228 may be very relevant to this. In short, the problem is that there are many Linux distros that may or may not include the native dependencies that libgit2 requires. In particular, the crypto libraries used for SSL, since libgit2 supports fetch/push. NB.GV has no need of this fetch/push functionality, but the fact NB.GV uses libgit2sharp, which uses libgit2, which uses libssl, means that you have to have the right libssl package installed on your Linux container for it to work.

There is ongoing work in the libgit2(sharp) community to finally tease apart this libssl dependency to make this much easier. And in the shorter term other workarounds are available or in progress.

For now, what I do when I'm working with docker images where it fails is install these two packages:

https:/AArnott/linux-buildagent/blob/4436e73950330663850968b84f609e85a0a7e038/Dockerfile#L9-L10

You could install these as part of your CI build (they install relatively quickly) or you could adjust your docker image to include them yourself, as I do above.

But ya, we plan to adopt any fixes to libgit2sharp soon after they're available to make this "just work" on an increasing number of Linux distros and docker images.

@tzachshabtay
Copy link

Just a thought, but have you considered ditching lib2git and just calling git from command line?

@AArnott
Copy link
Collaborator

AArnott commented Nov 14, 2018

Yes, I have. I haven't looked into it deeply, because my first take suggests it would be incredibly slow. We have to look for version.json files in the tree for each commit in history till we find certain significant changes. That would mean a lot of git.exe invocations. libgit2sharp is much faster than git.exe. Since this runs in people's builds, and can run many times in a build because it may run once for each project, perf is a very high priority.

@labsilva
Copy link
Author

Hi @AArnott, thanks for the quick reply!

I've tried adding the packages you said (libcurl3 and libssl1.0.0), but while using the .NET SDK Debian based image (the latest one) I can't locate those packages.

From what I could gather it seems they don't support it anymore and have transitioned to a newer version. This newer version doesn't work with libgit2 (or at least I wasn't able to get it to work).

I did manage to get it to work with .NET SDK Ubuntu (Bionic) based image, but that's not really an option for me at the moment.

Are there any other workarounds I can try for now, or should I just wait for a newer version?

Again, thanks for replying!

@AArnott
Copy link
Collaborator

AArnott commented Nov 15, 2018

I know that once certain packages are installed, the workaround (oddly) quits working.
I'm curious what drives people's choices in base images. Why must you use Debian?

As another workaround, try using an older version of NB.GV. The 2.1.x releases work on some distros that 2.2 doesn't.

@labsilva
Copy link
Author

I've tried with almost all releases from 2.1.x and I couldn't get it to work. I'll wait for a new version from libgit2.

As for why I must use Debian... it's not a case of must, more a case of not wanting to change right now; I have a reasonable number of applications running in my CI pipeline generating images and this change from Debian to Ubuntu would have to be properly validated, and right now it wouldn't be a good time.

I'll close this one (if it's OK with you), and will try again when you release a new version 😄

AArnott pushed a commit that referenced this issue Apr 1, 2024
Bumps [dotnet-coverage](https:/microsoft/codecoverage) from 17.10.2 to 17.10.3.
- [Commits](https:/microsoft/codecoverage/commits)

---
updated-dependencies:
- dependency-name: dotnet-coverage
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants