From 26aae360ce9d727d3a366e62fea22b7538006e64 Mon Sep 17 00:00:00 2001 From: Mark Edmondson Date: Sat, 30 Jan 2021 18:09:36 +0100 Subject: [PATCH] fix cr_setup for auth --- DESCRIPTION | 2 +- NEWS.md | 3 +- R/setup.R | 6 +++- inst/docker/packages/cloud_build.R | 8 +++-- inst/docker/packages/cloudbuild.yml | 46 +++++++++++++++++++++++++++-- 5 files changed, 56 insertions(+), 9 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index dca20c95..45bb4da9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: googleCloudRunner Type: Package Title: R Scripts in the Google Cloud via Cloud Run, Cloud Build and Cloud Scheduler -Version: 0.4.0.9000 +Version: 0.4.1 Authors@R: c(person("Mark", "Edmondson", email = "r@sunholo.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-8434-3881")), diff --git a/NEWS.md b/NEWS.md index f106bfd1..b82614ee 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,8 @@ -# googleCloudRunner 0.4.0.9000 +# googleCloudRunner 0.4.1 * Fix faulty test for `cr_setup_tests()` that was failing option 3 (#104) * Fix R and bash scripts failing builds and schedules if they included a `$` character in the script (#103 - thanks @yfarjoun) +* Fix `cr_setup_auth()` not being called in `cr_setup()` # googleCloudRunner 0.4.0 diff --git a/R/setup.R b/R/setup.R index df5a74ac..090bdb87 100644 --- a/R/setup.R +++ b/R/setup.R @@ -40,7 +40,11 @@ cr_setup <- function(){ do_function = gar_setup_env_check, env_arg = "GCE_AUTH_FILE", set_to = gar_setup_get_authenv(session_user = session_user, - env_arg = "GCE_AUTH_FILE"), + env_arg = "GCE_AUTH_FILE", + file = "googlecloudrunner-auth-key.json", + client_json = "GAR_CLIENT_JSON", + roles = cr_setup_role_lookup("local"), + default_key = "googlecloudrunner"), edit_option = we_edit, stop = TRUE, session_user = session_user) diff --git a/inst/docker/packages/cloud_build.R b/inst/docker/packages/cloud_build.R index 489ce2fb..5c431431 100644 --- a/inst/docker/packages/cloud_build.R +++ b/inst/docker/packages/cloud_build.R @@ -9,7 +9,9 @@ bs <- c( dir = "inst/docker/packages/") ) -built <- cr_build(cr_build_yaml(bs, timeout = 1200)) +build <- cr_build_yaml(bs, timeout = 2400) +cr_build_write(build, "inst/docker/packages/cloudbuild.yml") +# built <- cr_build(build) -s_me <- cr_build_schedule_http(built) -cr_schedule("packagetest-build", schedule = "15 9 * * 1", httpTarget = s_me) +s_me <- cr_build_schedule_http(build) +cr_schedule("packagetest-build2", schedule = "15 9 * * 1", httpTarget = s_me) diff --git a/inst/docker/packages/cloudbuild.yml b/inst/docker/packages/cloudbuild.yml index 2220064e..38d06983 100644 --- a/inst/docker/packages/cloudbuild.yml +++ b/inst/docker/packages/cloudbuild.yml @@ -1,16 +1,56 @@ steps: + - name: gcr.io/cloud-builders/gcloud + entrypoint: bash + args: + - -c + - gcloud secrets versions access latest --secret=github-ssh > /root/.ssh/id_rsa + id: git secret + volumes: + - name: ssh + path: /root/.ssh + - name: gcr.io/cloud-builders/git + entrypoint: bash + args: + - -c + - |- + chmod 600 /root/.ssh/id_rsa + cat <known_hosts + github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ== + EOF + cat </root/.ssh/config + Hostname github.com + IdentityFile /root/.ssh/id_rsa + EOF + mv known_hosts /root/.ssh/known_hosts + git config --global user.name "googleCloudRunner" + git config --global user.email "cr_buildstep_gitsetup@googleCloudRunner.com" + id: git setup script + volumes: + - name: ssh + path: /root/.ssh + - name: gcr.io/cloud-builders/git + args: + - clone + - git@github.com:MarkEdmondson1234/googleCloudRunner + - '.' + volumes: + - name: ssh + path: /root/.ssh - name: gcr.io/cloud-builders/docker args: - build - -f - - inst/docker/packages/Dockerfile + - Dockerfile - --tag - gcr.io/gcer-public/packagetools:latest - --tag - - gcr.io/gcer-public/packagetools:$BRANCH_NAME + - gcr.io/gcer-public/packagetools:$BUILD_ID - '.' + dir: inst/docker/packages/ - name: gcr.io/cloud-builders/docker args: - push - gcr.io/gcer-public/packagetools -#Generated by googleCloudRunner::cr_build_write at 2020-05-29 16:57:13 + dir: inst/docker/packages/ +timeout: 2400s +#Generated by googleCloudRunner::cr_build_write at 2021-01-23 17:28:55