Website Links

Friday, 12 April 2019

Google Cloud Build - Automating Function Deployment

The following is how to setup a basic google cloud function deployment using google cloud build.
  1. Go to Google Cloud Build (https://console.cloud.google.com/cloud-build/triggers)
  2. Add trigger
  3. Select your source
  4. Authenticate with your source
  5. Adjust your trigger settings
  6. Under Build Configuration, select cloudbuild.yaml
  7. Add substitution variable "_NAME" and provide the name of the function you want to deploy
  8. Add a cloudbuild.yaml to your repository e.g.
    steps:
    - name: 'gcr.io/cloud-builders/gcloud'
      args: ['beta', 'functions', 'deploy', '${_NAME}', 
             '--trigger-http']
    
Note: at some point you should add additional steps for unit tests to ensure that if any unexpected behaviour occurs your build will fail and your function will not be deployed

If you have any permission issues you might need to go to Project Settings > IAM and make sure a member exists with the following roles:
  • Cloud Build Service Account
  • Cloud Build Editor
  • Cloud Functions Developer

No comments:

Post a Comment