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

GIT not being recognised inside docker build inside gitlab #38

Open
augustocdias opened this issue May 18, 2021 · 5 comments
Open

GIT not being recognised inside docker build inside gitlab #38

augustocdias opened this issue May 18, 2021 · 5 comments

Comments

@augustocdias
Copy link

augustocdias commented May 18, 2021

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.

@lukaslueg
Copy link
Owner

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

built/src/lib.rs

Lines 421 to 429 in c7b082b

#[cfg(feature = "git2")]
fn write_git_version(manifest_location: &path::Path, w: &mut fs::File) -> io::Result<()> {
// CIs will do shallow clones of repositories, causing libgit2 to error
// out. We try to detect if we are running on a CI and ignore the
// error.
let (tag, dirty) = match util::get_repo_description(&manifest_location) {
Ok(Some((tag, dirty))) => (Some(tag), Some(dirty)),
_ => (None, None),
};

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.

@augustocdias
Copy link
Author

augustocdias commented May 19, 2021

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?

@lukaslueg
Copy link
Owner

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.

@augustocdias
Copy link
Author

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

@lukaslueg
Copy link
Owner

Then I don't know.

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

No branches or pull requests

2 participants