How to Deploy a Go App to Google Cloud Functions

Web
Deploy a Go app to Google Cloud Functions by building a Linux binary and using gcloud to configure and launch the service.

Deploy your Go app to Google Cloud Functions by building a binary, creating a deployment configuration, and running the deploy command.

  1. Build your Go binary for the target architecture. GOOS=linux GOARCH=amd64 go build -o main main.go

  2. Create a cloudbuild.yaml file to define the build and deployment steps. `echo 'steps:

  • name: "gcr.io/cloud-builders/gcloud" args: ["functions", "deploy", "my-function", "--runtime", "go121", "--entry-point", "HelloWorld", "--trigger-http"]' > cloudbuild.yaml`
  1. Deploy the function using the Cloud Build service. gcloud builds submit --config=cloudbuild.yaml

  2. Verify the deployment status in the Google Cloud Console. gcloud functions describe my-function --region us-central1