Get startedGet started for free

Deploying Cloud Run functions

1. Deploying Cloud Run functions

Let’s review the process to build and deploy Cloud Run functions from source code. The deployment process takes your function source code and configuration settings and builds a runnable image. Cloud Run functions automatically manages the image in order to handle requests to your function. A user deploying Cloud Run functions must have the Cloud Functions Developer IAM role or a role that includes the same permissions. To deploy Cloud Run functions, a user must also be assigned the Service Account User IAM role on the Cloud Run functions runtime service account. You can deploy your function from the Google Cloud console, using Cloud Build, using Cloud Code, or with the gcloud CLI. To deploy Cloud Run functions, specify the gen2 flag. The region flag specifies the region in which to deploy your function. The runtime flag specifies the language runtime of your function. The source flag specifies the location of your function source code. The function can be located on your local machine, in Cloud Storage, or in a source repository. Specify a function or class name in your source code as the entry point of your cloud function with the entry-point flag. The function or class code is executed when your function runs. Cloud Code is a tool that simplifies the development and deployment of Cloud Run functions. It allows you to create, deploy, and invoke functions directly within your IDE, making the process more efficient. To specify the type of trigger and related configuration for your function, provide trigger flags. Refer to the gcloud functions deploy command documentation for more details. You can specify the location of your function source code for deployment with the source flag. You can deploy your function from a local machine. The value of the source flag is a local file system path to the root directory of the function source code. Optionally, use the stage-bucket flag to specify a Cloud Storage bucket to upload your source code to as part of deployment. You can exclude unnecessary files with the . gcloudignore file. Cloud Storage. The value of the source flag is the cloud storage path to the bucket that contains the function source code packaged as a zip file. Your function source files must be located at the root of the zip file. In Cloud Run functions (1st generation), the account performing the deployment needs permission to read from the bucket. In Cloud Run functions, the Cloud Run functions service agent needs permission to read from the bucket. A source repository. The value of the source flag is a source repository reference to the location of your function source code. You can deploy your function source code from a revision in your repository by specifying revisions/revision name in the source repository path. To specify the location of the source code other than the repository root, append the paths/source_directory_path to the source repository path. The Cloud Run functions service agent must have the Source Repository Reader (roles/source.reader) IAM role on the repository. Deploying from Cloud Source Repositories also enables you to deploy code hosted in a GitHub or Bitbucket repository. You can also write and deploy a function directly from the Google Cloud console using the provided inline editor. The editor contains a left pane to view and select source files and the right pane to edit a source file. Let’s review the build process for Cloud Run functions. When you deploy your function's source code to Cloud Run functions, that source is stored in a Cloud Storage bucket. Cloud Build is a service that executes builds on Google Cloud infrastructure. Cloud Build automatically builds your function source code into a container image, and pushes that image to Artifact Registry. Cloud Run functions then accesses this image when it needs to run the container to execute your function. The process of building the image is entirely automatic and requires no direct input from you. The Cloud Build API must be enabled for your project. All the resources used in the build process execute in your own user project, and you have access to all the build logs through Cloud Logging. Cloud Run functions uses Artifact Registry to store the images built from your function source code. Artifact Registry is a service that is used to store and manage software artifacts in private repositories, including container images, and language packages. Artifact Registry integrates with Cloud Build to store the packages from your builds.

2. Let's practice!

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.