Gcloud credentials on host machine
When running cloud build as CI with GitHub, the code is stored in the /workspace directory which is then automatically mapped as volume to a cloud runner.
In my case, I have to mount the /workspace to a different directory inside my docker container. This is possible by providing the -v run argument, e.g.:
- name: 'gcr.io/cloud-builders/docker'
args:
- 'run'
- '-v'
- '/workspace:[some_directory]'
- '[some_image_name]'
- '[some_command]'
id: 'example'
waitFor: ['-']
Generally, this works well. However in my example, [some_command] needs to access gcloud credentials which can't be found inside the docker container.
It seems that cloudbuild per default does not only mount -v /workspace:/workspace to a build runner but also mounts the credentials to /builder/home/.config/gcloud (-v [unknown_dir]:/builder/home/.config/gcloud). To make my example work I need to add the [unknown_dir] to the command above.
- name: 'gcr.io/cloud-builders/docker'
args:
- 'run'
- '-v'
- '/workspace:/[some_directory]'
- '-v'
- '[unknown_dir]:/root/.config/gcloud'
- '[some_image_name]'
- '[some_command]'
id: 'example'
waitFor: ['-']
Does anyone know the path of the gcloud credentials on the host machine ([unknown_dir])? This should be part of the documentation.
I think this is your answer https://cloud.google.com/cloud-build/docs/build-config#network
This is genius, thank you!