Google Cloud Functions allows you to deploy small logical units of code (i.e. functions). While it is already possible to deploy these functions from a Google Cloud Storage bucket or directly from the inline editor (e.g. for prototyping purposes), did you know that you can take advantage of the Google Cloud Repository to host the Cloud Functions source code and automate these deployments? You could for instance trigger a new deploy after each git push
.
Let's see how.
We'll assume you already have a working Google Cloud Repository (how to setup a Cloud Repository) with the following configuration:
- projectID:
project-123
- repository name:
default
- default branch:
master
- function name:
function-123
The repository URL should look like this: https://source.developers.google.com/p/project-123/r/default
.
Deploying from this repository is quit easy:
$ gcloud beta functions deploy function-123 --source https://source.developers.google.com/projects/project-123/repos/default/moveable-alises/master --entry-point function-123 --trigger-http
Please note that the --source
URL used to deploy the function is different from the repository URL!