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

GitVersionTask on the dotnet SDK docker image (microsoft/dotnet:2.1-sdk; Debian 9) #1473

Closed
gerwim opened this issue Sep 12, 2018 · 18 comments
Closed
Milestone

Comments

@gerwim
Copy link

gerwim commented Sep 12, 2018

So, I'm using GitVersionTask in my Docker build (using the officical microsoft/dotnet:2.1-sdk image). The issue I was having is the following error:

Could not determine assembly version: System.TypeInitializationException: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. ---> System.DllNotFoundException: Unable to load shared library 'git2-15e1193' or one of its dependencies.

How I fixed it, is by install the library system wide and symlinking the location it's searching (used the LD_DEBUG env var to check what it was doing). In my Dockerfile I now have:

FROM microsoft/dotnet:2.1-sdk as builder

# Fix GitVersionTask build issue
RUN apt-get update && \
        apt-get install -y libgit2-dev && \
        ln -s /usr/lib/x86_64-linux-gnu/libgit2.so /lib/x86_64-linux-gnu/libgit2-15e1193.so

.... other build steps

I created the issue just to let you know. The current version (15e1193) is hardcoded above, so it might change depending on the LibGit2Sharp.Core.NativeMethods library version is used.

@brunobertechini
Copy link

How are you using GitVersionTask inside this docker image? Can u share pls ?

@gerwim
Copy link
Author

gerwim commented Sep 19, 2018

How are you using GitVersionTask inside this docker image? Can u share pls ?

Just install the NuGet package GitVersionTask (I have version 4.0.0-beta0014 installed) and build your project. Check the output dll file and you'll see the assembly version has been updated.

@dazinator
Copy link
Member

dazinator commented Oct 10, 2018

For running on net.core 2.1.0 perhaps it's because you need #1422 ?

@arturcic
Copy link
Member

@gerwim can you validate this agains the latest v.4.0.0 version and close the issue ? Thanks

@gerwim
Copy link
Author

gerwim commented Oct 23, 2018

@arturcic I've installed GitVersionTask 4.0.0 and tried the build the project inside the microsoft/dotnet:2.1-sdk docker image, but still same error. I also tried to install libgit2-dev without symlinking the libraries, but to no avail:

MSBUILD : warning : WARN [10/23/18 7:59:06:37] Could not determine assembly version: System.TypeInitializationException: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. ---> System.DllNotFoundException: Unable to load shared library 'git2-15e1193' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libgit2-15e1193: cannot open shared object file: No such file or directory

@dazinator
Copy link
Member

dazinator commented Oct 23, 2018

As above, I think you need the .net core 2.1 support which is in #1422 and not yet merged..

Otherwise try with a net core sdk 2.0 docker image.

@gerwim
Copy link
Author

gerwim commented Oct 23, 2018

@dazinator Yeah, that's what I thought however Artur explicitly asked me to redo the test with the 2.1 version. Either way, let's wait until the PR is merged. ;-)

@arturcic
Copy link
Member

I did that because the docker images that we currently have for version 4.0.0 are using microsoft/dotnet:2.1-runtime and they do work.

@dazinator
Copy link
Member

dazinator commented Oct 23, 2018

@arturcic my guess is that the docker images we have currently for 2.1.0 are just calling dotnet gitversion which is slightly different from calling dotnet build (or msbuild) within the image to build a csproj file under dotnet sdk 2.1.0 cli, which loads and executes GitVersionTask. As far as I know the PR in question enables GitVersionTask to run in that second scenario. If things already work fine on 2.1.0 (including gitversiontask) then it would make me question the purpose of that outstanding PR..

@arturcic
Copy link
Member

you're absolutely right

@dazinator
Copy link
Member

dazinator commented Oct 23, 2018

We should probably rename that PR to make it super clear that its a gitversiontask thing. GitVersion itself already runs on 2.1.0 as you have said! But i think there may have been some other changes in it like the global tool stuff so I guess its now more of a conglomorate of things :-)

@j2ghz
Copy link

j2ghz commented Oct 24, 2018

I have the same problem, here is a sample Dockerfile:

FROM microsoft/dotnet:sdk
WORKDIR /app
RUN dotnet new console
RUN dotnet add package GitVersionTask
RUN dotnet build

At this time I tested it sdk is equivalent to 2.1.403-sdk-stretch 2.1-sdk-stretch 2.1.403-sdk 2.1-sdk sdk latest

@dazinator
Copy link
Member

@j2ghz I assume if you try that on a 2.0.0 sdk it works? It sounds like you are also waiting for this PR to allow GitVersionTask to execute on >= 2.1.0 (simultaneously deprecating support for sdk 1.1.0)

@j2ghz
Copy link

j2ghz commented Oct 24, 2018

I guess so. I used the fix from the first post, which helped. In the end I turned gitversion off in docker builds, since I get Could not determine assembly version: System.InvalidOperationException: Could not find a 'develop' or 'master' branch, neither locally nor remotely., even after unshallow. Since it works at Appveyor and Travis, just not at Docker Hub, I think I'll just move the build to one of them.

@arturcic
Copy link
Member

#1659

@driseley
Copy link

driseley commented May 14, 2019

If it helps - it appears as if the current version of the GitVersion.Tool (5.0.0-beta2-91) ships a version of the libgit2 lib (libgit2-15e1193.so) that depends on OpenSSL 1.0.0, which is not present in microsoft/dotnet:sdk, which is based on Debian Stretch.

This (rather ugly) workaround seems to work, by installing OpenSSL 1.0.0 from Debian Jessie:

Dockerfile:

FROM mcr.microsoft.com/dotnet/core/sdk:2.2

ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.dotnet/tools

COPY jessie.list /etc/apt/sources.list.d/jessie.list

RUN apt-get update -y && \
    apt-get install -y libssl1.0.0 && \
    apt-get clean -y && \
    dotnet tool install --global GitVersion.Tool --version 5.0.0-beta2-91 -v q

jsessie.list:

deb http://httpredir.debian.org/debian jessie main contrib non-free
deb-src http://httpredir.debian.org/debian jessie main contrib non-free

deb http://security.debian.org/ jessie/updates main contrib non-free
deb-src http://security.debian.org/ jessie/updates main contrib non-free
root@7067a21bc27d:~# dotnet gitversion
{
  "Major":0,
  "Minor":1,
  "Patch":0,
  "PreReleaseTag":"",
  "PreReleaseTagWithDash":"",
  "PreReleaseLabel":"",
  "PreReleaseNumber":"",
  "WeightedPreReleaseNumber":"",
  "BuildMetaData":0,
  "BuildMetaDataPadded":"0000",
  "FullBuildMetaData":"0.Branch.master.Sha.3cbdf2470549030115f933f7993a8b1eab38b40c",
  "MajorMinorPatch":"0.1.0",
  "SemVer":"0.1.0",
  "LegacySemVer":"0.1.0",
  "LegacySemVerPadded":"0.1.0",
  "AssemblySemVer":"0.1.0.0",
  "AssemblySemFileVer":"0.1.0.0",
  "FullSemVer":"0.1.0+0",
  "InformationalVersion":"0.1.0+0.Branch.master.Sha.3cbdf2470549030115f933f7993a8b1eab38b40c",
  "BranchName":"master",
  "Sha":"3cbdf2470549030115f933f7993a8b1eab38b40c",
  "ShortSha":"3cbdf24",
  "NuGetVersionV2":"0.1.0",
  "NuGetVersion":"0.1.0",
  "NuGetPreReleaseTagV2":"",
  "NuGetPreReleaseTag":"",
  "VersionSourceSha":"3cbdf2470549030115f933f7993a8b1eab38b40c",
  "CommitsSinceVersionSource":0,
  "CommitsSinceVersionSourcePadded":"0000",
  "CommitDate":"2019-05-14"
}

@arturcic
Copy link
Member

arturcic commented Jun 27, 2019

With the latest version there is no need for the workaround.

You can have a look at the way we ship the docker image with gitversion included https://github.com/GitTools/GitVersion/blob/master/src/Docker/netcoreapp2.1/linux/debian-9/Dockerfile

There is no need to install libgit2-dev and add symlink

@arturcic
Copy link
Member

As LibGit2Sharp was upgraded to version 0.26 in #1713, I think this problem is fixed. Please reopen this issue if the problem persists.

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

6 participants