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

Do an example of scheduling a Cloud Run app for R code #114

Open
MarkEdmondson1234 opened this issue Mar 15, 2021 · 2 comments
Open

Do an example of scheduling a Cloud Run app for R code #114

MarkEdmondson1234 opened this issue Mar 15, 2021 · 2 comments
Milestone

Comments

@MarkEdmondson1234
Copy link
Owner

Maybe add the option to the "Schedule R script" gadget to have a plumber API endpoint as an option.

run_app <- cr_run_schedule_http(
       "https://example-ewjogewawq-ew.a.run.app/echo?msg=blah",
      http_method = "GET"
     )

cr_schedule("cloud-run-scheduled", schedule = "4 16 * * *", httpTarget = run_me)
MarkEdmondson1234 added a commit that referenced this issue Mar 15, 2021
@MarkEdmondson1234
Copy link
Owner Author

Need to add the scheduler email as a role:
https://cloud.google.com/run/docs/triggering/using-scheduler#command-line

    auth_step <- cr_buildstep_gcloud(
      args = c("gcloud",
               "run", "services", "add-iam-policy-binding",
               name,
               sprintf("--member=serviceAccount:%s",cr_email_get()),
               "--role=roles/run.invoker",
               "--platform", "managed",
               name),
      id = "auth cloudrun",
      ...)

??

MarkEdmondson1234 added a commit that referenced this issue Mar 17, 2021
@MarkEdmondson1234
Copy link
Owner Author

It seems impossible for the invoker for private Cloud Run to be the same email as the one deploying it (which is weird if you ask me - the error was "this@email does not have permission to act on behalf of this@email").

Down that rabbit hole the Cloud run deployment process (via cr_buildstep_run()) will now create a dedicated service account for its own deployment and give it access. This brings the need for users to generate that email, which is by default called "my-app-invoker" - tried to explain in the docs

# for unauthenticated apps create a HttpTarget
run_me <- HttpTarget(
  uri = "https://public-ewjogewawq-ew.a.run.app/echo?msg=blah",
  http_method = "GET"
)
cr_schedule("cloud-run-scheduled", schedule = "16 4 * * *",
            httpTarget = run_me)

# for authenticated Cloud Run apps - create with allowUnauthenticated=FALSE
cr_deploy_run("my-app", allowUnauthenticated = TRUE)

## End(Not run)

# deploying via R will help create a service email called my-app-cloudrun-invoker
cr_run_email("my-app")

## Not run: 
# use that email to schedule the Cloud Run private micro-service

# schedule the endpoint
my_run_name <- "my-app"
my_app <- cr_run_get(my_run_name)
email <- cr_run_email(my_run_name)
endpoint <- paste0(my_app$status$url, "/fetch_stuff")

app_sched <- cr_run_schedule_http(endpoint,
                                  http_method = "GET",
                                  email = email)

cr_schedule("cloud-run-scheduled-1",
            schedule = "4 16 * * *",
            httpTarget = app_sched)

@MarkEdmondson1234 MarkEdmondson1234 added this to the CRAN 0.5.0 milestone Dec 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant