R/buildsteps_templates.R
cr_buildstep_nginx_setup.Rd
Setup nginx for Cloud Run in a buildstep
cr_buildstep_nginx_setup(html_folder, ...)
The folder that will hold the HTML for Cloud Run
This uses a premade bash script that sets up a Docker container ready for Cloud Run running nginx
Other arguments passed to cr_buildstep_bash
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_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:51 > ProjectId set to my-project
#> [1] "my-project"
cr_bucket_set("my-bucket")
#> ℹ 2022-03-26 19:55:51 > Bucket set to my-bucket
#> [1] "my-bucket"
cr_region_set("europe-west1")
#> ℹ 2022-03-26 19:55:51 > Region set to europe-west1
#> [1] "europe-west1"
html_folder <- "my_html"
run_image <- "gcr.io/my-project/my-image-for-cloudrun"
cr_build_yaml(
steps = c(
cr_buildstep_nginx_setup(html_folder),
cr_buildstep_docker(run_image, dir = html_folder),
cr_buildstep_run(
name = "running-nginx",
image = run_image,
concurrency = 80
)
)
)
#> ==cloudRunnerYaml==
#> steps:
#> - name: ubuntu
#> args:
#> - bash
#> - -c
#> - |-
#> echo "
#> server {
#> listen \$$$${PORT};
#> server_name localhost;
#> location / {
#> root /usr/share/nginx/html;
#> index index.html index.htm;
#> }
#> }" > default.template
#>
#> cat <<EOF >Dockerfile
#> FROM nginx
#> COPY . /usr/share/nginx/html
#> COPY default.template /etc/nginx/conf.d/default.template
#> CMD envsubst < /etc/nginx/conf.d/default.template > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'
#> EOF
#>
#> cat default.template
#> cat Dockerfile
#> id: setup nginx
#> dir: my_html
#> - name: gcr.io/cloud-builders/docker
#> args:
#> - build
#> - -f
#> - Dockerfile
#> - --tag
#> - gcr.io/my-project/my-image-for-cloudrun:latest
#> - --tag
#> - gcr.io/my-project/my-image-for-cloudrun:$BUILD_ID
#> - '.'
#> id: building image
#> dir: my_html
#> - name: gcr.io/cloud-builders/docker
#> args:
#> - push
#> - gcr.io/my-project/my-image-for-cloudrun
#> id: pushing image
#> dir: my_html
#> - name: gcr.io/google.com/cloudsdktool/cloud-sdk:alpine
#> args:
#> - gcloud
#> - run
#> - deploy
#> - running-nginx
#> - --image
#> - gcr.io/my-project/my-image-for-cloudrun
#> - --region
#> - europe-west1
#> - --platform
#> - managed
#> - --concurrency
#> - '80'
#> - --port
#> - default
#> - --max-instances
#> - default
#> - --memory
#> - 256Mi
#> - --cpu
#> - '1'
#> - --clear-env-vars
#> - --allow-unauthenticated
#> id: deploy cloudrun
#> - name: gcr.io/google.com/cloudsdktool/cloud-sdk:alpine
#> args:
#> - gcloud
#> - run
#> - services
#> - add-iam-policy-binding
#> - --region=europe-west1
#> - --member=allUsers
#> - --role=roles/run.invoker
#> - --platform=managed
#> - running-nginx
#> id: auth cloudrun