Skip to content

Instantly share code, notes, and snippets.

@Qwerios
Last active October 23, 2018 10:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Qwerios/2ec8a62e1fb88b3e5b7b8aaa3c93a99c to your computer and use it in GitHub Desktop.
Save Qwerios/2ec8a62e1fb88b3e5b7b8aaa3c93a99c to your computer and use it in GitHub Desktop.
Google Cloud Builder setup to auto-deploy to a kuberneter engine cluster
# We can use this cloudbuild.yaml setup with a trigger type tag
# on Google Cloud Build using default variable substitution.
#
# Use environment substitution in the trigger to add the additional parameters:
#
# _CLUSTER = kubernetes engine cluster. Ex. my-test-cluster
# _DEPLOYMENT = deployment name Ex. my-project
# _CONTAINER = container name within deployment. Ex. my-project-api
# _GCS_ZONE = compute engine zone. Ex. europe-west-1c
#
# Reference docs:
# https://cloud.google.com/cloud-build/docs/configuring-builds/build-test-deploy-artifacts
# https://cloud.google.com/cloud-build/docs/configuring-builds/substitute-variable-values
#
steps:
# Build the docker image using git tag as a version
- name: 'gcr.io/cloud-builders/docker'
args: ["build", "-t", "gcr.io/$PROJECT_ID/$REPO_NAME:$TAG_NAME", "."]
# Publish the docker image to google repository
- name: 'gcr.io/cloud-builders/docker'
args: ["push", "gcr.io/$PROJECT_ID/$REPO_NAME:$TAG_NAME"]
# Update test cluster deployment to this new image
- name: 'gcr.io/cloud-builders/kubectl'
args:
- set
- image
- deployment
- $_DEPLOYMENT
- $_CONTAINER=gcr.io/$PROJECT_ID/$REPO_NAME:$TAG_NAME
env:
- 'CLOUDSDK_COMPUTE_ZONE=$_GCS_ZONE'
- 'CLOUDSDK_CONTAINER_CLUSTER=$_CLUSTER'
images: ['gcr.io/$PROJECT_ID/$REPO_NAME:$TAG_NAME']
@Qwerios
Copy link
Author

Qwerios commented Oct 1, 2018

This does require the first deployment to be done by hand. It only updates the image of an existing deployment. This was an intended safety feature for us to not redeploy disabled software on build.

@Qwerios
Copy link
Author

Qwerios commented Oct 23, 2018

Also ensure your cloudbuilder service agent has the kubernetes engine admin role as per the docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment