0
votes

I have a project in which I need to use gcloud commands, I need to build with the proper credentials, seems gcloud commands don't use the variable GOOGLE_APPLICATION_CREDENTIALS, so I set the auth in RUN step in docker

FROM google/cloud-sdk
COPY . usr/src/app
WORKDIR /usr/src/app 
RUN gcloud auth activate-service-account --key-file=/usr/src/app/credentials.json

but when I build the image and enter to the container I have no access to gcloud commands, lets say

gcloud projects list

I have the next answer

WARNING: Could not open the configuration file: [/root/.config/gcloud/configurations/config_default]. ERROR: (gcloud.projects.list) You do not currently have an active account selected.

credentials are inside the container because if I do manually I can run the next command and everything works well.

gcloud auth activate-service-account --key-file=/usr/src/app/credentials.json

how can add the credentials to exist by default in build?, does the RUN step may not take effect when building the image.

1

1 Answers

1
votes

You are correct, gcloud does not check GOOGLE_APPLICATION_CREDENTIALS.

I think you're not using the Google-approved container image: Google Cloud SDK Docker

See Usage for a good way to mount service account credentials into the container.