Create a build step to build and push a docker image
cr_buildstep_docker(
image,
tag = c("latest", "$BUILD_ID"),
location = ".",
projectId = cr_project_get(),
dockerfile = "Dockerfile",
kaniko_cache = FALSE,
build_args = NULL,
push_image = TRUE,
...
)
The image tag that will be pushed, starting with gcr.io or created by combining with projectId
if not starting with gcr.io
The tag or tags to be attached to the pushed image - can use Build
macros
Where the Dockerfile to build is in relation to dir
The projectId
Specify the name of the Dockerfile found at location
If TRUE will use kaniko cache for Docker builds.
additional arguments to pass to docker build
,
should be a character vector.
if kaniko_cache = FALSE
and
push_image = FALSE
, then the docker image is simply built and not
pushed
Further arguments passed in to cr_buildstep
Setting kaniko_cache = TRUE
will enable caching of the layers of the Dockerfile, which will speed up subsequent builds of that Dockerfile. See Using Kaniko cache
If building multiple tags they don't have to run sequentially - set waitFor = "-"
to build concurrently
Other Cloud Buildsteps:
cr_buildstep_bash()
,
cr_buildstep_decrypt()
,
cr_buildstep_df()
,
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()
,
cr_buildstep()
cr_project_set("my-project")
#> ℹ 2022-03-26 19:55:49 > ProjectId set to my-project
#> [1] "my-project"
cr_bucket_set("my-bucket")
#> ℹ 2022-03-26 19:55:49 > Bucket set to my-bucket
#> [1] "my-bucket"
cr_buildstep_docker("gcr.io/my-project/my-image")
#> [[1]]
#> ==cloudRunnerBuildStep==
#> name: gcr.io/cloud-builders/docker
#> args:
#> - build
#> - -f
#> - Dockerfile
#> - --tag
#> - gcr.io/my-project/my-image:latest
#> - --tag
#> - gcr.io/my-project/my-image:$BUILD_ID
#> - '.'
#> id: building image
#>
#> [[2]]
#> ==cloudRunnerBuildStep==
#> name: gcr.io/cloud-builders/docker
#> args:
#> - push
#> - gcr.io/my-project/my-image
#> id: pushing image
#>
cr_buildstep_docker("my-image")
#> [[1]]
#> ==cloudRunnerBuildStep==
#> name: gcr.io/cloud-builders/docker
#> args:
#> - build
#> - -f
#> - Dockerfile
#> - --tag
#> - gcr.io/my-project/my-image:latest
#> - --tag
#> - gcr.io/my-project/my-image:$BUILD_ID
#> - '.'
#> id: building image
#>
#> [[2]]
#> ==cloudRunnerBuildStep==
#> name: gcr.io/cloud-builders/docker
#> args:
#> - push
#> - gcr.io/my-project/my-image
#> id: pushing image
#>
cr_buildstep_docker("my-image", tag = "$BRANCH_NAME")
#> [[1]]
#> ==cloudRunnerBuildStep==
#> name: gcr.io/cloud-builders/docker
#> args:
#> - build
#> - -f
#> - Dockerfile
#> - --tag
#> - gcr.io/my-project/my-image:$BRANCH_NAME
#> - '.'
#> id: building image
#>
#> [[2]]
#> ==cloudRunnerBuildStep==
#> name: gcr.io/cloud-builders/docker
#> args:
#> - push
#> - gcr.io/my-project/my-image
#> id: pushing image
#>
# setting up a build to trigger off a Git source:
my_image <- "gcr.io/my-project/my-image"
my_repo <- RepoSource("github_markedmondson1234_googlecloudrunner",
branchName = "master"
)
if (FALSE) {
docker_yaml <- cr_build_yaml(steps = cr_buildstep_docker(my_image))
built_docker <- cr_build(docker_yaml, source = my_repo)
# make a build trigger so it builds on each push to master
cr_buildtrigger("build-docker", trigger = my_repo, build = built_docker)
# add a cache to your docker build to speed up repeat builds
cr_buildstep_docker("my-image", kaniko_cache = TRUE)
# building using manual buildsteps to clone from git
bs <- c(
cr_buildstep_gitsetup("github-ssh"),
cr_buildstep_git(c("clone", "git@github.com:MarkEdmondson1234/googleCloudRunner", ".")),
cr_buildstep_docker("gcr.io/gcer-public/packagetools",
dir = "inst/docker/packages/"
)
)
built <- cr_build(cr_build_yaml(bs))
}