> For the complete CircleCI developer hub index, see [llms.txt](https://circleci.com/developer/llms.txt)

# circleci/gcp-cloud-run

'Build and deploy stateless images to Google Cloud Run as serverless applications. Repo: https://github.com/CircleCI-Public/gcp-cloud-run-orb Home: https://cloud.google.com/run/'


## Commands

### build

'Build your container image using Cloud Run Build. Learn more: https://cloud.google.com/run/docs/quickstarts/build-and-deploy'


| Parameter | Type | Default | Description |
|---|---|---|---|
| `args` | string |  | Add any additional arguments not explicitly defined as a parameter. Find additional arguments here: https://cloud.google.com/sdk/gcloud/reference/beta/builds/submit |
| `config` | string |  | The YAML or JSON file to use as the build configuration file. |
| `source` | string |  | The location of the source to build. The location can be a directory on a local disk or a gzipped archive file (.tar.gz) in Google Cloud Storage. If a dockerfile is present in the working directory, this parameter may be left blank. |
| `tag` | string |  | The tag to use with a "docker build" image creation. Cloud Build will run a remote "docker build -t $TAG .", where $TAG is the tag provided by this flag. The tag must be in the gcr.io/* or *.gcr.io/* namespaces. Specify a tag if you want Cloud Build to build using a Dockerfile instead of a build config file. If you specify a tag in this command, your source must include a Dockerfile. For instructions on building using a Dockerfile see https://cloud.google.com/cloud-build/docs/quickstart-docker. |

### create_gke_cluster

'Create a cluster and enable it for Cloud Run for Anthos on Google Cloud Learn more: https://cloud.google.com/run/docs/quickstarts/prebuilt-deploy-gke'


| Parameter | Type | Default | Description |
|---|---|---|---|
| `addons` | string | HorizontalPodAutoscaling,HttpLoadBalancing,Istio,CloudRun | Addons (https://cloud.google.com/kubernetes-engine/reference/rest/v1/projects.zones.clusters#AddonsConfig) are additional Kubernetes cluster components. Addons specified by this flag will be enabled. The others will be disabled.  |
| `args` | string |  | Add any additional arguments not explicitly defined as a parameter. Find additional arguments here: https://cloud.google.com/sdk/gcloud/reference/beta/container/clusters/create#--enable-stackdriver-kubernetes |
| `cluster-name` | string |  | The name of the cluster |
| `enable-stackdriver-kubernetes` | boolean | false | Enable Stackdrive logging for Kubernetes (https://cloud.google.com/monitoring/kubernetes-engine/legacy-stackdriver/logging) |
| `machine-type` | string | n1-standard-1 | The type of machine to use for nodes. The list of predefined machine types is available using the following command. |
| `scopes` | string | gke-default | Specifies scopes for the node instances. |
| `zone` | string |  | Compute zone (e.g. us-central1-a) for the cluster. |

### delete_gke_cluster

Delete an existing GCloud cluster.


| Parameter | Type | Default | Description |
|---|---|---|---|
| `args` | string |  | Add any additional arguments not explicitly defined as a parameter. Find additional arguments here: https://cloud.google.com/sdk/gcloud/reference/beta/container/clusters/create#--enable-stackdriver-kubernetes |
| `cluster-name` | string |  | The name of the cluster |
| `zone` | string |  | Compute zone (e.g. us-central1-a) for the cluster. |

### deploy

'Deploy your containerized application to Google Cloud Run. Learn more: https://cloud.google.com/run/docs/deploying For the managed service: After deployment, the service URL will be accessible via the $GCP_DEPLOY_ENDPOINT environment variable.'


| Parameter | Type | Default | Description |
|---|---|---|---|
| `args` | string |  | Add any additional arguments not explicitly defined as a parameter. Find additional arguments here: https://cloud.google.com/sdk/gcloud/reference/beta/run/deploy |
| `cluster` | string |  | ID of the cluster or fully qualified identifier for the cluster. Required on "gke" and "kubernetes" platforms. |
| `cluster-location` | string |  | Zone in which the cluster is located. Required on "gke" and "kubernetes" platforms. |
| `image` | string |  | Name of the container image to deploy (e.g. gcr.io/cloudrun/hello:latest). |
| `platform` | enum | managed | Target platform |
| `region` | string |  | Required on "managed" platform. |
| `service-name` | string |  | What is the name of the service being deployed? |
| `unauthenticated` | boolean | false | Whether to enable allowing unauthenticated access to the service. |

### init

Install and initialize the GCP CLI for Google Cloud Run. Ensure to set the required environment variables.


| Parameter | Type | Default | Description |
|---|---|---|---|
| `gcloud-service-key` | env_var_name | GCLOUD_SERVICE_KEY | Required environment variable. Name of environment variable storing the full service key JSON file for the Google project. |
| `google-compute-zone` | env_var_name | GOOGLE_COMPUTE_ZONE | Required environment variable. The Google compute zone to connect with via the gcloud CLI. |
| `google-project-id` | env_var_name | GOOGLE_PROJECT_ID | Required environment variable. The Google project ID to connect with via the gcloud CLI. |

## Executors

### default

Base CircleCI docker image.


| Parameter | Type | Default | Description |
|---|---|---|---|
| `tag` | string | stable | Pick a specific cimg/base image tag: https://hub.docker.com/r/cimg/base/tags
 |

## Examples

### build_and_deploy_on_gke

Automatically build and deploy a docker container using the Cloud Run managed platform.


```yaml
jobs:
  build_and_deploy_gke:
    docker:
      - image: cimg/base:stable
    steps:
      - checkout
      - cloudrun/init
      - cloudrun/create_gke_cluster:
          cluster-name: example-cluster-${CIRCLE_BUILD_NUM}
          enable-stackdriver-kubernetes: true
          machine-type: n1-standard-4
          scopes: cloud-platform
          zone: us-east1
      - cloudrun/build:
          tag: gcr.io/${GOOGLE_PROJECT_ID}/test-${CIRCLE_SHA1}
      - cloudrun/deploy:
          cluster: example-cluster-${CIRCLE_BUILD_NUM}
          cluster-location: us-east1
          image: gcr.io/${GOOGLE_PROJECT_ID}/test-${CIRCLE_SHA1}
          platform: gke
          service-name: example-service-${CIRCLE_BUILD_NUM}
orbs:
  cloudrun: circleci/gcp-cloud-run@x.y
version: 2.1
workflows:
  build_and_deploy_to_gke_workflow:
    jobs:
      - build_and_deploy_gke
```

### build_and_deploy_on_managed

Automatically build and deploy a docker container using the Cloud Run managed platform.


```yaml
jobs:
  build_and_deploy:
    docker:
      - image: cimg/base:stable
    steps:
      - checkout
      - cloudrun/init
      - cloudrun/build:
          tag: gcr.io/${GOOGLE_PROJECT_ID}/test-${CIRCLE_SHA1}
      - cloudrun/deploy:
          image: gcr.io/${GOOGLE_PROJECT_ID}/test-${CIRCLE_SHA1}
          platform: managed
          region: us-east1
          service-name: example-service
          unauthenticated: true
      - run:
          command: >
            # A simple example of how a deployed managed service could be
            verified or further tested.

            # This step will send request our "API" and fail if there is
            unexpected output.

            GCP_API_RESULTS=$(curl -s "$GCP_DEPLOY_ENDPOINT")

            if [ "$GCP_API_RESULTS" != "Hello World!" ]; then
              echo "Result is unexpected"
              echo 'Result: '
              curl -s "$GCP_DEPLOY_ENDPOINT"
              exit 1;
            fi
          name: Test managed deployed service.
orbs:
  cloudrun: circleci/gcp-cloud-run@x.y
version: 2.1
workflows:
  build_and_deploy_to_managed_workflow:
    jobs:
      - build_and_deploy
```