Cloud Functions runs user code in containers created using Google's
Cloud Native buildpacks.
You can create these containers yourself and
run them locally using
Docker and the
pack
tool.
Introduction Video
In this video, Matt introduces Buildpacks on Google Cloud:
Setup
Before proceeding, make sure you have the pack
tool
and Docker installed.
Building your function
Selecting a signature type
In order to build your function, you'll first have to determine your function's signature type. The Functions Frameworks support three different signature types for incoming events:
Function type | Signature type | Description | Runtimes |
---|---|---|---|
HTTP-triggered functions |
http
|
Functions that receive and respond to HTTP requests. | All |
Background functions |
event
|
Cloud Functions-specific event format | Java, Node, Go, and Python |
CloudEvent functions |
cloudevent
|
Industry-standard event format | Ruby and .NET. |
Building your function
To build your function into a portable Docker container using buildpacks, use
the pack build
command shown below. Replace the following variables:
- YOUR_FUNCTION_SIGNATURE_TYPE should be your function's signature type (as shown in the table above)
- YOUR_FUNCTION_NAME with the entry-point of your function
- YOUR_BUILDPACK_IMAGE_NAME with the name you wish to give the resulting container
Node.js
pack build \ --builder gcr.io/buildpacks/builder:v1 \ --env GOOGLE_RUNTIME=nodejs --env GOOGLE_FUNCTION_SIGNATURE_TYPE=YOUR_FUNCTION_SIGNATURE_TYPE \ --env GOOGLE_FUNCTION_TARGET=YOUR_FUNCTION_NAME \ YOUR_BUILDPACK_IMAGE_NAME
Python
pack build \ --builder gcr.io/buildpacks/builder:v1 \ --env GOOGLE_RUNTIME=python --env GOOGLE_FUNCTION_SIGNATURE_TYPE=YOUR_FUNCTION_SIGNATURE_TYPE \ --env GOOGLE_FUNCTION_TARGET=YOUR_FUNCTION_NAME \ YOUR_BUILDPACK_IMAGE_NAME
Go
pack build \ --builder gcr.io/buildpacks/builder:v1 \ --env GOOGLE_RUNTIME=go --env GOOGLE_FUNCTION_SIGNATURE_TYPE=YOUR_FUNCTION_SIGNATURE_TYPE \ --env GOOGLE_FUNCTION_TARGET=YOUR_FUNCTION_NAME \ YOUR_BUILDPACK_IMAGE_NAME
Java
pack build \ --builder gcr.io/buildpacks/builder:v1 \ --env GOOGLE_RUNTIME=java --env GOOGLE_FUNCTION_SIGNATURE_TYPE=YOUR_FUNCTION_SIGNATURE_TYPE \ --env GOOGLE_FUNCTION_TARGET=YOUR_FUNCTION_NAME \ YOUR_BUILDPACK_IMAGE_NAME
C#
pack build \ --builder gcr.io/buildpacks/builder:v1 \ --env GOOGLE_RUNTIME=dotnet --env GOOGLE_FUNCTION_SIGNATURE_TYPE=YOUR_FUNCTION_SIGNATURE_TYPE \ --env GOOGLE_FUNCTION_TARGET=YOUR_FUNCTION_NAME \ YOUR_BUILDPACK_IMAGE_NAME
This command packages your function into a runnable Docker container that can process HTTP requests matching one of the signature types specified in the table above.
Calling your function
See the calling running functions page for instructions on how to interact with your locally-running function.