0
votes

I have a Go Dockerfile from https://cloud.google.com/run/docs/quickstarts/build-and-deploy with a one line change so that I can tell what version I'm running:

RUN go build -ldflags "-X main.Version=$(git describe --always)" -mod=readonly -v -o server

When I build locally via docker build . and test, there is no problem with git describe, however if I submit the Docker to be built via gcloud builds submit it fails with:

fatal: not a git repository (or any of the parent directories): .git

How do I build my Cloud Run docker image so it has this Git version reference?

1

1 Answers

0
votes

When you perform gcloud builds submit, all the project files aren't sent to Cloud Build. The command take into account your .gitignore file and the .gcloudignore file. If you haven't a .gcloudignore a default behavior is enforced in addition of the .gitignore file directive. More detail here

So, to fix this, create a .gcloudignore file with only the file to exclude for your Build. So, let the .git/ (don't add it in the file) and it will work.