Last active
October 23, 2018 10:24
-
-
Save Qwerios/2ec8a62e1fb88b3e5b7b8aaa3c93a99c to your computer and use it in GitHub Desktop.
Google Cloud Builder setup to auto-deploy to a kuberneter engine cluster
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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'] |
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
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.