cloud-builders: Can't get .git directory to show up in remote builds
I’m submitting a remote build with gcloud container builds submit --config cloudbuild.yaml and no matter what I try, the .git directory is not showing up in the temporary tarballs. My Dockerfile needs to access the .git directory for the build and obviously it can’t find it and all my remote builds fail (local builds work fine).
There is no .dockerignore, no .gitignore, no .gcloudignore, and no “Some files were not included in the source upload.” message like I get in other projects where I use those ignore files.
If I create a different hidden directory:
mkdir .foo
touch .foo/bar
that directory does show up in the tarball, so I know it’s not excluding all hidden directories.
Is there some hardcoding specifically to exclude .git when creating the tarball?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 29 (5 by maintainers)
@bendory is there a different logic applied when using the GCB GitHub App? I’m trying to get private submodules working, but the extracted tarball doesn’t contain a .git folder
I think it’s worth reopening this issue. I appreciate the thorough answer, @bendory, but it seems the
.gcloudignoreisn’t used when builds are triggered from GitHub.Or is there a separate issue tracking that in particular?
Really the solution here is just for the Cloud Build app to send
.git/with the rest of the files when a build is triggered, it’s clearly something that people need and its unintuitive that only this one directory is missing.Where would be the right place to file an issue about this?
Indeed, if you look at the code for
gcloudignore, you’ll see that we generally ignore a.gitdirectory, since it is rather unusual to want to upload this as part of your build context.If you want it, you have several options:
.gcloudignore(touch .gcloudignore).gcloudignore(or.gitignore) that ignores the files you don’t want but doesn’t ignore.git.gcloudignorethat explicitly includes.git(echo '!.git' > .gcloudignore)gcloud config set gcloudignore/enabled falseSee the gcloudignore documentation for further details.
@saminiemi Your workaround doesn’t work if you want to take advantage of the “Build on PR” feature that’s only available with the Cloud Build GitHub App repo 😦
Also experiencing this issue with the new Cloud Build GitHub App triggers. Have attempted to explicitly add
!.gitto the.gcloudignorefile with no success.@bendory @wlynch - have you been able to recreate this on your end?
Why is this closed? Having a
.gitdirectory is still required for github triggered builds.That assumption is false. We need the
.gitdirectory for several reasons, includinggit describe,git submodule, andgit lfsHere’s a
cloudbuild.yamlfile I made to hack around this. This checks out the.gitdirectory and checks out a private submodule with git-lfs files.We do this instead of moving the repo:
And for authentication we use this project: https://github.com/connectedcars/auth-wrapper
I’m also running into this: with the
.gitdirectory is not being added to my image in Cloud Build triggered by GitHub, despite having an empty.gcloudignorepresent.