MarkEdmondson1234 / googleCloudRunner

Easy R scripts on Google Cloud Platform via Cloud Run, Cloud Build and Cloud Scheduler
https://code.markedmondson.me/googleCloudRunner/
Other
81 stars 26 forks source link

cr_setup_test() error #145

Closed brancengregory closed 2 years ago

brancengregory commented 2 years ago

Hi, thanks so much for your work on this package! It is invaluable.

I'm having an issue where cr_setup() runs in full, successfully. I then try to run tests, and each build finishes successfully but then returns this error:

`Error : lexical error: invalid char in json text. googlecloudrunner@ (right here) ------^

googlecloudrunner@.iam.gserviceaccount.com does not have storage.objects.get access to the Google Cloud Storage object.Error in textConnection(logs) : invalid 'text' argument`

Any advice would be much appreciated.

brancengregory commented 2 years ago

I have verified that both my build and googlecloudrunner service accounts have Storage Admin and Storage Object Admin permissions

MarkEdmondson1234 commented 2 years ago

That's very odd! May I see your sessionInfo() eg CRAN or GitHub version. Also I notice a dot after the @ in the email, is that a typo?

brancengregory commented 2 years ago

For sure!

R version 4.1.1 (2021-08-10) Platform: x86_64-apple-darwin17.0 (64-bit) Running under: macOS Monterey 12.0.1

Matrix products: default LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib

locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages: [1] stats graphics grDevices datasets utils methods
[7] base

other attached packages: [1] containerit_0.6.0.9004 googleCloudRunner_0.4.1.9000

loaded via a namespace (and not attached): [1] Rcpp_1.0.7 googleCloudStorageR_0.6.0 [3] ps_1.6.0 assertthat_0.2.1
[5] rprojroot_2.0.2 digest_0.6.28
[7] utf8_1.2.2 mime_0.12
[9] R6_2.5.1 futile.options_1.0.1
[11] evaluate_0.14 httr_1.4.2
[13] pillar_1.6.4 rlang_0.4.12
[15] curl_4.3.2 rstudioapi_0.13
[17] miniUI_0.1.1.1 callr_3.7.0
[19] googleAuthR_1.4.0 rmarkdown_2.11
[21] desc_1.4.0 stringr_1.4.0
[23] shiny_1.7.1 jose_1.2.0
[25] compiler_4.1.1 httpuv_1.6.3
[27] xfun_0.28 pkgconfig_2.0.3
[29] askpass_1.1 versions_0.3
[31] stevedore_0.9.4 htmltools_0.5.2
[33] openssl_1.4.5 tibble_3.1.6
[35] codetools_0.2-18 fansi_0.5.0
[37] crayon_1.4.2 later_1.3.0
[39] jsonlite_1.7.2 xtable_1.8-4
[41] lifecycle_1.0.1 magrittr_2.0.1
[43] formatR_1.11 semver_0.2.0
[45] zip_2.2.0 cli_3.1.0
[47] stringi_1.7.5 cachem_1.0.6
[49] renv_0.14.0 fs_1.5.0
[51] promises_1.2.0.1 xml2_1.3.2
[53] futile.logger_1.4.3 ellipsis_0.3.2
[55] shinyFiles_0.9.1 vctrs_0.3.8
[57] rjson_0.2.20 lambda.r_1.2.4
[59] tools_4.1.1 glue_1.5.0
[61] purrr_0.3.4 processx_3.5.2
[63] fastmap_1.1.0 yaml_2.2.1
[65] gargle_1.2.0 BiocManager_1.30.16
[67] automagic_0.5.1 memoise_2.0.0
[69] knitr_1.36 usethis_2.1.3

brancengregory commented 2 years ago

I was using the CRAN version but switched to the main github branch as a debugging measure. Also sorry for the ugly sessionInfo formatting. Thanks for such a quick response.

brancengregory commented 2 years ago

The dot in the email is just from me taking out the project name. It shows the full valid service account name in the R console output

brancengregory commented 2 years ago

Hmmm, switched back to the CRAN version and now I'm getting a regular "Something is wrong with Cloud Run setup" error.

brancengregory commented 2 years ago

This is the GCP log:

Step #0 - "deploy cloudrun": ERROR: (gcloud.beta.run.deploy) User [418847747096@cloudbuild.gserviceaccount.com] does not have permission to access namespaces instance [development-207013] (or it may not exist): Google Cloud Run Service Agent does not have permission to get access tokens for the service account 418847747096-compute@developer.gserviceaccount.com. Please give service-418847747096@serverless-robot-prod.iam.gserviceaccount.com permission iam.serviceAccounts.getAccessToken on the service account. Alternatively, if the service account is unspecified or in the same project you are deploying in, ensure that the Service Agent is assigned the Google Cloud Run Service Agent role roles/run.serviceAgent.

brancengregory commented 2 years ago

I'm just not sure what is left to try. I've verified that my cloud build service account has the Cloud Run Service Agent permission, as well as Cloud Run Admin

MarkEdmondson1234 commented 2 years ago

Is it an older GCP project? Sometimes the default service accounts aren't present in older ones. It's complaining the Service Agent role is not assigned to the cloud build email (cloud build > settings)

Did you set up via the package's setup auth functions? It should assign that role for you. Otherwise double check it's all in same GCP project and if there are any stray .Renviron files overriding your expected settings. Failing that delete that file and restart the setup function again that should take you through the flow of setting up the right roles etc. for the service accounts.

brancengregory commented 2 years ago

Yeah, this project is probably 4-5 years old. Those are some good leads. I'll give it a try. Thanks!

MarkEdmondson1234 commented 2 years ago

Yes older projects don't have a specific service account owned by Google.

brancengregory commented 2 years ago

New project and following the great documentation did the trick. Many thanks Mark

MarkEdmondson1234 commented 2 years ago

Great! Glad you are up and runnning.