cloud-builders icon indicating copy to clipboard operation
cloud-builders copied to clipboard

Gcloud credentials on host machine

Open scopelf opened this issue 7 years ago • 2 comments

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.

scopelf avatar Aug 22 '19 09:08 scopelf

I think this is your answer https://cloud.google.com/cloud-build/docs/build-config#network

LanceSandino avatar Jan 28 '20 07:01 LanceSandino

This is genius, thank you!

scopelf avatar Feb 02 '20 10:02 scopelf