GoogleCloudPlatform / cloud-run-button

Let anyone deploy your GitHub repos to Google Cloud Run with a single click
https://cloud.run
Apache License 2.0
523 stars 91 forks source link

How to get the current gcp project id in hook scripts? #240

Closed evil-shrike closed 1 year ago

evil-shrike commented 1 year ago

In hooks scripts in app.json (prebuild/postbuild/precreate/postcreate) we can call some shell commands in the context of the current ephemeral Cloud Shell, but it looks like there's no GCP project id set there. Though the project should have been selected on the first stage of the startup script of the VM, so at the moment of hooks execution it's known. So, the question is how can I access the current selected GCP project id in a hook script?

And regardless of this, a suggestion - set the current project id via gcloud (gcloud config set project xxx), so it could be used implicitly.

evil-shrike commented 1 year ago

I'll answer to myself. The variable with the current gcp project id is GOOGLE_CLOUD_PROJECT. So in a hook script we can use:

gcloud config set project ${GOOGLE_CLOUD_PROJECT}