Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GCLOUD_PROJECT is deprecared in favor of GOOGLE_CLOUD_PROJECT + avoid using it at all #251

Closed
steren opened this issue Dec 18, 2018 · 9 comments
Assignees
Labels
🚨 This issue needs some love. triage me I really want to be triaged.

Comments

@steren
Copy link
Contributor

steren commented Dec 18, 2018

The sample relies on the GCLOUD_PROJECT environment variable (see https://github.com/GoogleCloudPlatform/nodejs-getting-started/blob/master/2-structured-data/config.js#L27)

However, this variable is now deprecated and is not present in newer versions of the Node.js runtimes for App Engine.

Instead, developers should rely on the GOOGLE_CLOUD_PROJECT environment variable.

@jcapogna
Copy link

Aha. I'm just going through these tutorials and I found myself having to manually set the GCLOUD_PROJECT env variable in my startup script.

The google cloud libraries being used still seem to want GCLOUD_PROJECT to be set. At least I was getting errors about GCLOUD_PROJECT before I started manually setting it. Does this mean we need to set GCLOUD_PROJECT and GOOGLE_CLOUD_PROJECT or do the new libraries expect GOGOLE_CLOUD_PROJECT?

@steren
Copy link
Contributor Author

steren commented Jan 17, 2019

Actually, the client library teams tells me that the best practice is to leverage the metadata server present on all GCP runtimes.

This means that if you have a client object, most languages expose it as a property on the client, e.g, storage_client.project.

The GOOGLE_CLOUD_PROJECT is not present on many GCP runtimes (e.g. GKE or GCE)

@steren steren changed the title GCLOUD_PROJECT is deprecared in favor of GOOGLE_CLOUD_PROJECT GCLOUD_PROJECT is deprecared in favor of GOOGLE_CLOUD_PROJECT + avoid using it at all Jan 26, 2019
@fhinkel fhinkel self-assigned this Feb 5, 2019
fhinkel added a commit that referenced this issue Feb 6, 2019
Locally, users should use GOOGLE_APPLICATION_CREDENTIALS. On GCP,
the metadata is used autmatically.

This commit does not change the GKE sample.

Ref: #251
fhinkel added a commit that referenced this issue Feb 6, 2019
Locally, users should use GOOGLE_APPLICATION_CREDENTIALS. On GCP,
the metadata is used autmatically.

This commit does not change the GKE sample.

Ref: #251
fhinkel added a commit that referenced this issue Feb 6, 2019
Locally, users should use GOOGLE_APPLICATION_CREDENTIALS. On GCP,
the metadata is used autmatically.

This commit does not change the GKE sample.

Ref: #251
fhinkel added a commit that referenced this issue Feb 15, 2019
Locally, users should use GOOGLE_APPLICATION_CREDENTIALS. On GCP,
the metadata is used autmatically.

This commit does not change the GKE sample.

Ref: #251
@zbjornson
Copy link

zbjornson commented May 28, 2019

best practice is to leverage the metadata server present on all GCP runtimes

google-auth-library (for Node.js) forks a process to run gcloud config to get the project ID, and last I looked, it prioritizes that over using the metadata server:

https://github.com/googleapis/google-auth-library-nodejs/blob/37bb8c7cd0a6501103274284d9cddd6816cc881e/src/auth/googleauth.ts#L177-L182

Forking a process isn't safe on Linux because of nodejs/node#25382; we routinely get crashes from the GCP client libs. I think that should be addressed before Google globally recommends not using an env var. An env var is also faster than making a req to the metadata server.

@GitTom
Copy link

GitTom commented Aug 2, 2019

I'm no longer able to access GCLOUD_PROJECT or GOOGLE_CLOUD_PROJECT on the Node 10 runtime in Firebase Functions or Google Cloud Functions.

This is consistent with the warning/advice given above, but it is a problem for me.

It seems that the metadata server is now the recommended solution, but that puzzles me because my understanding was that that is only for GCE.

Never-the-less I tried to use it (via the 'gcp-metadata' node module which is quite widely used) with GCF and FBF and I think I tried it with Cloud Run too, and it failed to work on all of them. I could keep trying to debug the problem on those, but I didn't even think it was supposed to work on them.

I gotta' say, just reading 'process.env.GOOGLE_CLOUD_PROJECT' sure was simple. If getting rid of it was motivated by making these platforms conform more closely to k-native then I applaud that motivation, but am not sure how to proceed.

@steren
Copy link
Contributor Author

steren commented Aug 2, 2019

I have this snippet that shows how to get the project-id from the metadata server in Node.js: https://gist.github.com/steren/6bc5e011632e8c0f13cf8578d7944d97

@GitTom
Copy link

GitTom commented Aug 4, 2019

Yes, that does work for me, thank you. (It doesn't work in emulator, but I expected that.) I'm not sure why the gcpMetadata module didn't work in Functions and this does - but I'm glad to have something that does.

It is unfortunate, in the context of FaaS services, to have to do a request each time for a static value, but I guess there are options to minimize that cost: I will load it into global so it only has to be requested once per instance, and I guess one could setup something in deployment to set an env var with the desired static metadata values.

@steren
Copy link
Contributor Author

steren commented Aug 5, 2019

Another alternative is for you to set the project name as a user environment variable at deployment time.

@GitTom
Copy link

GitTom commented Aug 5, 2019

Yes, that is what I meant in my last sentence (but I think my wording was a bit unclear) and I think it is a good solution.

@fhinkel
Copy link
Contributor

fhinkel commented Sep 1, 2019

Obsolete with planned rewrite of the tutorial.

@fhinkel fhinkel closed this as completed Sep 1, 2019
@yoshi-automation yoshi-automation added 🚨 This issue needs some love. triage me I really want to be triaged. labels Apr 6, 2020
augustine-linzl added a commit to augustine-linzl/GoogleCloudPlatformw that referenced this issue Nov 27, 2021
Locally, users should use GOOGLE_APPLICATION_CREDENTIALS. On GCP,
the metadata is used autmatically.

This commit does not change the GKE sample.

Ref: GoogleCloudPlatform/nodejs-getting-started#251
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚨 This issue needs some love. triage me I really want to be triaged.
Projects
None yet
Development

No branches or pull requests

6 participants