cr_buildstep {googleCloudRunner} | R Documentation |
Create a yaml build step
Description
Helper for creating build steps for upload to Cloud Build
Usage
cr_buildstep(
name,
args = NULL,
id = NULL,
prefix = "gcr.io/cloud-builders/",
entrypoint = NULL,
dir = "",
env = NULL,
waitFor = NULL,
volumes = NULL,
secretEnv = NULL
)
Arguments
name |
name of docker image to call appended to |
args |
character vector of arguments |
id |
Optional id for the step |
prefix |
prefixed to name - set to "" to suppress. Will be suppressed if |
entrypoint |
change the entrypoint for the docker container |
dir |
The directory to use, relative to /workspace e.g. /workspace/deploy/ |
env |
Environment variables for this step. A character vector for each assignment |
waitFor |
Whether to wait for previous buildsteps to complete before running. Default it will wait for previous step. |
volumes |
volumes to connect and write to |
secretEnv |
A list of secrets stored in Secret Manager referred to in args via a |
Details
This uses R to make building steps for cloudbuild.yml files harder to make mistakes with, and also means you can program creation of cloud build steps for use in R or other languages. Various templates with common use cases of buildsteps are also available that wrap this function, refer to the "See Also" section.
WaitFor
By default each buildstep waits for the previous, but if you pass "-"
then it will start immediately, or if you pass in a list of ids it will wait for previous buildsteps to finish who have that id. See Configuring Build Step Order for details.
Build Macros
Fields can include the following variables, which will be expanded when the build is created:-
$PROJECT_ID: the project ID of the build.
$BUILD_ID: the autogenerated ID of the build.
$REPO_NAME: the source repository name specified by RepoSource.
$BRANCH_NAME: the branch name specified by RepoSource.
$TAG_NAME: the tag name specified by RepoSource.
$REVISION_ID or $COMMIT_SHA: the commit SHA specified by RepoSource or resolved from the specified branch or tag.
$SHORT_SHA: first 7 characters of $REVISION_ID or $COMMIT_SHA.
Or you can add your own custom variables, set in the Build Trigger. Custom variables always start with $_ e.g. $_MY_VAR
secretEnv
You can pass secrets that are stored in Secret Manager directly instead of using a dedicated buildstep via cr_buildstep_secret
Within the code passed to args
those secrets are referred to via $$SECRET_NAME
. If used then cr_build_yaml must also include the availableSecrets
argument.
See Also
Creating custom build steps how-to guide
Other Cloud Buildsteps:
cr_buildstep_bash()
,
cr_buildstep_decrypt()
,
cr_buildstep_df()
,
cr_buildstep_docker()
,
cr_buildstep_edit()
,
cr_buildstep_extract()
,
cr_buildstep_gcloud()
,
cr_buildstep_gitsetup()
,
cr_buildstep_mailgun()
,
cr_buildstep_nginx_setup()
,
cr_buildstep_packagetests()
,
cr_buildstep_pkgdown()
,
cr_buildstep_run()
,
cr_buildstep_r()
,
cr_buildstep_secret()
,
cr_buildstep_slack()
,
cr_buildstep_targets()
Examples
cr_project_set("my-project")
cr_bucket_set("my-bucket")
# creating yaml for use in deploying cloud run
image <- "gcr.io/my-project/my-image:$BUILD_ID"
cr_build_yaml(
steps = c(
cr_buildstep("docker", c("build", "-t", image, ".")),
cr_buildstep("docker", c("push", image)),
cr_buildstep("gcloud", c(
"beta", "run", "deploy", "test1",
"--image", image
))
),
images = image
)
# use premade docker buildstep - combine using c()
image <- "gcr.io/my-project/my-image"
cr_build_yaml(
steps = c(
cr_buildstep_docker(image),
cr_buildstep("gcloud",
args = c(
"beta", "run", "deploy",
"test1", "--image", image
)
)
),
images = image
)
# list files with a new entrypoint for gcloud
cr_build_yaml(steps = cr_buildstep("gcloud", c("-c", "ls -la"),
entrypoint = "bash"
))
# to call from images not using gcr.io/cloud-builders stem
cr_buildstep("alpine", c("-c", "ls -la"), entrypoint = "bash", prefix = "")
# to add environment arguments to the step
cr_buildstep("docker", "version", env = c("ENV1=env1", "ENV2=$PROJECT_ID"))
# to add volumes wrap in list()
cr_buildstep("test", "ls", volumes = list(list(name = "ssh", path = "/root/.ssh")))