Deploy a Cloud Function with Cloud Build
Contributed by the Google Cloud community. Not official Google documentation.
This tutorial demonstrates how to create and deploy a Cloud Function with Cloud Build.
- Use Cloud Build to deploy a Cloud Function.
- Use code written in the Go programming language to process incoming HTTP requests.
Set up your environment
- Create a project in the Cloud Console.
- Enable billing for your project.
- Create a GitHub repository for your project.
Enable the Cloud Functions API:
gcloud services enable cloudfunctions.googleapis.com
Add the Cloud Build GitHub app to your GitHub account and repository.
Create the directory and file structure in the GitHub repository.
You can use the file tree from the source for this tutorial as a starting point.
Put a file named
cloudbuild.yamlin the root directory and the code for the Cloud Function in a separate directory, as in the following file tree:
│ .gitignore │ cloudbuild.yaml └───code function.go
Connect the repository with Cloud Build
- In the Cloud Console, go to the Cloud Build page.
- Choose Triggers.
- Click Connect repository.
- Create a push trigger so that Cloud Build will run when you push to the master branch.
After you have connected the repository with Cloud Build, Cloud Build will run, build, test, and deploy your Cloud Function each time you push to the repository.
You can view a list of your builds on the Cloud Builds page of the Cloud Console.