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

Missing Git Information with Docker build #216

Closed
remy-burney-pf opened this issue Jan 31, 2023 · 4 comments
Closed

Missing Git Information with Docker build #216

remy-burney-pf opened this issue Jan 31, 2023 · 4 comments
Labels

Comments

@remy-burney-pf
Copy link

Missing Git Information with Docker build

Steps to Reproduce

My application is packaged into a docker image.
In the docker file I'm building the application with dotnet build and dotnet publish, but the Git information is not being generated.

The extract of my docker file looks a bit like the below example

COPY ["Frontend.csproj", "Frontend/"]

RUN dotnet restore "Frontend/Frontend.csproj"
COPY . .

WORKDIR "/src/Frontend"
RUN dotnet build "Frontend.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Frontend.csproj" -c Release -o /app/publish /p:UseAppHost=false

I'm not sure how the package works, but I'm guessing it needs the ".git" folder or something like that to work and pull the information.

Did anybody faced a similar situation, and resolved it.
Do you have any example or best practice to make this work as part of the DockerFile.

Expected Behavior

The Dll should have the "TheAssembly.Git" class with the correct Git information.

Actual Behaviour

If I look at the compiled code, I can see that the Git class doesn't have any of the Git information.

internal class ThisAssembly
{
  public class Git
  {
    public const bool IsDirty = false;
    public const string IsDirtyString = "false";
    public const string RepositoryUrl = "";
    public const string Branch = "master";
    public const string Commit = "";
    public const string Sha = "";
    public const string CommitDate = "";
    public const string Commits = "0";
    public const string Tag = "";
    public const string BaseTag = "";

  }
}

It probably makes sense because there wouldn't be any ".git" folder to use.

@kzu
Copy link
Member

kzu commented Jan 31, 2023

It's not about a .git folder. GitInfo actually uses the git CLI. So, you need to be building an actually cloned repo, and the docker image needs to also have git installed and in the PATH.

@kzu kzu closed this as completed Jan 31, 2023
@zai-tm
Copy link

zai-tm commented Aug 15, 2023

I don't mean to bump but i'm having the exact same issue and installing git in the container didn't work. my dockerfile looks like this:

FROM mcr.microsoft.com/dotnet/runtime:7.0 AS base
WORKDIR /app
RUN apt-get -y update
RUN apt-get -y install git

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["XaiSharp/XaiSharp.csproj", "XaiSharp/"]
RUN dotnet restore "XaiSharp/XaiSharp.csproj"
ADD . .
COPY . .
WORKDIR "/src/XaiSharp"
RUN dotnet build "XaiSharp.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "XaiSharp.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "XaiSharp.dll"]

@kzu
Copy link
Member

kzu commented Aug 25, 2023

Before the build, run (for example) git log -n1 and see if you get something. My gut feeling tells me git is either not installed or the folder where the build is running is not actually a properly cloned repo.

@BigBang1112
Copy link

BigBang1112 commented May 25, 2024

Two troubleshooting tips in case anyone else is having this problem:

  • .dockerignore - VS autogenerates this file with the **/.git ignore. Comment out this line.
  • Be 100% sure the .git directory is copied correctly. For me, only COPY .git/ ./.git/ worked properly.

@devlooped devlooped locked and limited conversation to collaborators Sep 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants