Deploying Cloud Functions


Deployments work by uploading an archive containing your function's source code to a Cloud Storage bucket. Once the source code has been uploaded, Cloud Build automatically builds your code into a container image and pushes that image to either Artifact Registry or Container Registry. Cloud Functions uses that image to create the container that executes your function.

More specifically:

  1. Starting a deployment zips your source code, including all files except those that match a .gcloudignore pattern.
  2. Once your source code has been zipped and uploaded, a build is submitted to Cloud Build. The build uses the pack build command with to build your container. This does the following:

    • Uses the base Ubuntu image.
    • Installs the language runtime.
    • Installs the Functions Framework if not already present.
    • Installs user dependencies.
    • Exports the OCI image.

Caching helps make these steps faster. See this video for an overview of the process.

For more information about where a function's image is stored, see Building Cloud Functions Images.

Deployment options

You can deploy Cloud Functions from your local machine, from your GitHub or Bitbucket source repository (via Cloud Source Repositories), or from the Cloud Functions API directly.

When deploying, Cloud Functions looks for particular files, depending on your runtime. See Writing Cloud Functions for details. Before your function's deployment is finalized, Cloud Functions will send your function a test request to confirm that it deployed successfully.

Migrating between deployments

A function's first deployment may take several minutes to complete while the underlying infrastructure is provisioned. Redeploying an existing function is faster, and incoming traffic will be automatically migrated to your function's newest version.

Basic concepts

As you learn about the different ways to deploy functions, it is helpful to understand some basic terminology. When you deploy a function, it is displayed in the Cloud console, as shown below. In particular, note the Name and Executed Function fields:

  • The Name field is the registered name you assign to your function.
  • The Executed Function field is the name of the actual function in your source code that is executed when the deployed function gets called.

These two fields can have the same name, or the names can be different. Notice below that the first two functions have registered names that are different from the executed function names. The last function uses the same name for both fields: helloHttp.

Screenshot that shows function deployment process

Building and Testing Locally

Cloud Functions execute in runtime environments based on open source languages and frameworks so you can build and test your functions locally using standard runtimes and development tools.

You can also use the Functions Framework to run and debug your functions locally for supported runtimes to make testing and debugging easier.

Next steps