built icon indicating copy to clipboard operation
built copied to clipboard

GIT not being recognised inside docker build inside gitlab

Open augustocdias opened this issue 3 years ago • 5 comments

Hi,

I couldn't find the reason but I have a project that the GIT consts are all set to none when built inside gitlab ci. I run the build in a rust:alpine based image. I've tried to print out all the info I could and couldn't find any reason for it to fail:

  • The cargo manifest path is pointing to the root of the project
  • I've printed the folder structure and the .git directory was in the root folder
  • I've printed the output file from built and it is indeed setting the git consts to None
  • I've added git2 dependency as a build dependency and called Repository::discover(&Path::new(env!("CARGO_MANIFEST_DIR"))) to see if it was failing but it was returning Ok(repo).
  • I have a project with the following structure
|_ build.rs -> I call built here
|_ Cargo.toml -> here I have a workspace config + the dependencies from the root project
|_ src
|___ main.rs
|___ build_info.rs -> the generated code is appended here
|_ crate1
|___ Cargo.toml
|___ src
|_____ lib.rs
|_ crate2
|___ Cargo.toml
|___ src
|_____ lib.rs

I have another project that has a simpler structure that everything works as expected. So I imagined it could be something related to my project structure, but I have no idea what could it be.

augustocdias avatar May 18 '21 14:05 augustocdias

This is (as I now realize) undocumented, but expected behavior:

https://github.com/lukaslueg/built/blob/c7b082bf092c51a6cae7b9ee5da5eff896551936/src/lib.rs#L421-L429

libgit2, which is used to retrieve git-information is unable to query repositories that are based on shallow clones. This has been a long-standing issue which we can do nothing about I'm afraid.

lukaslueg avatar May 18 '21 15:05 lukaslueg

Okay... I understand why it doesn't work... But now I ask why it works in my another project that runs in very similar conditions (same gitlab ci and almost identical stage config)? And why when I call Repository::discover myself in the build.rs it works?

augustocdias avatar May 19 '21 08:05 augustocdias

Probably because the other repo has a shorter commit history and its root is within the commit-depth that GitLab's CI will check out.

You may be able to tell GitLab's CI to do a full (non-shallow) checkout.

lukaslueg avatar May 19 '21 17:05 lukaslueg

Gitlab set the depth to 50 by default and what you said is not the case. The other project is older and contains a lot more commits. This project is new and probably doesn't even have the 50 commits to limit the depth

augustocdias avatar May 19 '21 18:05 augustocdias

Then I don't know.

lukaslueg avatar May 19 '21 21:05 lukaslueg