cloudtasker icon indicating copy to clipboard operation
cloudtasker copied to clipboard

[Question/docs] How is the GCP project id retrieved when running on GCP?

Open tiagojsag opened this issue 2 years ago • 3 comments

Hi everyone,

I'm deploying a RoR app on GCP Cloud Run, that uses Cloudtasker to schedule async workloads using GCP Cloud Tasks. While reviewing the gem's docs (specifically https://github.com/keypup-io/cloudtasker#cloud-tasks-authentication--permissions) there is a link to Google Cloud Authentication guide. that mentions that the project id (and other things, like credentials) are loaded auto-magically from the GCP runtime environment, and thus we as devs don't have to worry about loading said values.

Based on that "project id is loaded magically for you", I have an app running on GCP Cloud Run where Cloudtasker.config.gcp_project_id is NOT set from a string/env var/anything. However, when scheduling an async task, I am getting the following on Cloud Run logs:

2022-05-17 17:09:15.255 CEST 15:09:15 web.1 | E, [2022-05-17T15:09:15.252525 #20] ERROR -- : [569d56a4-2004-4661-84ae-c98bd548867b] Missing GCP project ID. Default 2022-05-17 17:09:15.255 CEST 15:09:15 web.1 | Please specify a project ID in the cloudtasker configurator.

When looking into this, I noticed that Cloudtasker's link to Google's docs on authentication actually point to the docs of the google-cloud-bigquery gem, and the equivalent docs for the google-cloud-tasks gem here don't mention anything about the project id being loaded automatically.

So my question is: do I need to explicitly define Cloudtasker.config.gcp_project_id and Cloudtasker.config.gcp_location_id even when running on GCP (and, in which case, it might be good to update the docs here to make this explicit and help noobs like get have a smoother experience), or am I missing something?

In case you think updating the docs will be helpful, I am happy to volunteer for that, as a way of saying "thank you" for this gem.

Thanks

tiagojsag avatar May 17 '22 15:05 tiagojsag

Hey @tiagojsag , that's a good point. I should probably be more specific in the docs around that point.

To answer your question: yes, you need to explicitly define Cloudtasker.config.gcp_project_id and Cloudtasker.config.gcp_location_id. These two parameters tell Cloudtasker where to create the background tasks.

What is automagically discovered is the identity of the service creating the tasks (the IAM role running the app or the GCP user when in development). This is handled by the Google Auth SDK directly. You do not need to explicitly specify a token or role in the Cloudtasker config.

Note: I've updated the authentication link to point to the general authentication guide, not the bigquery one.

alachaum avatar May 18 '22 07:05 alachaum

Thanks for answering my question! Do you think it's worth making this more explicit in the current docs?

tiagojsag avatar May 18 '22 09:05 tiagojsag

Yes definitely 😊 Feel free to propose a wording via a PR.

Otherwise I'll do it.

alachaum avatar May 18 '22 10:05 alachaum