Supercharge your Cloud Building with these custom Builders!
meta-cloud-builder
: Build custom Cloud Build images (builders) from a config file.meta-triggers
: Deploy all your Cloud Build Triggers from config files (yaml
or json
).Build custom Cloud Build images (builders) from a config file.
Manually build this image into your project once (I suggest Cloud Shell).
# clone
git clone https://github.com/jthegedus/meta-cloud-builders
# build
cd meta-cloud-builders/meta-cloud-builder
gcloud builds submit .
# validate
gcloud container images list --filter meta-cloud-builder
Create a .yaml
or .json
file with repos and the cloud-builder you wish to build into your project:
# .cicd/builders/custom-builders.yaml
- repo: https://github.com/jthegedus/meta-cloud-builder
builders:
- meta-cloud-builder
- meta-triggers
- repo: https://github.com/GoogleCloudPlatform/cloud-builders-community
builders:
- cancelot
- cache
then pass this config file into the meta-cloud-builder
step as an arg:
# .cicd/builders.cloudbuild.yaml
steps:
- name: gcr.io/$PROJECT_ID/meta-cloud-builder
id: "build custom cloud build builder(s) from a config file"
waitFor:
- "-"
args:
- ".cicd/builders/custom-builders.yaml"
- "--async"
tags:
- cloud-builders
This builder then invokes gcloud builds submit ...
for cloud-builders defined in the configuration file. You can pass any gcloud builds submit
flags to the builder except the --config
and SOURCE
aspects. See the flags here.
Deploy all your Cloud Build Triggers from config files (
yaml
orjson
).
Pair this builder with a Trigger and have it run on changes to your Trigger config files.
Manually build this image into your project once.
# clone
git clone https://github.com/jthegedus/meta-cloud-builders
# build
cd meta-cloud-builders/meta-triggers
gcloud builds submit .
# validate
gcloud container images list --filter meta-triggers
The builder runs by recursively checking a directory for files matching a sufix. The defaults are:
.
- the repo root.*\.trigger\.(json|yaml)
- a Grep -E regexYou can override the params, but they are positionaly args so to override the suffix
you must override the dir
.
# .cicd/apply-triggers.cloudbuild.yaml
steps:
- name: gcr.io/$PROJECT_ID/meta-triggers
id: "Watch for changes to all Cloud Build Triggers in provided dir"
waitFor:
- "-"
args:
- ".cicd/"
- ".*\\.trigger\\.(json|yaml)"
Now we want to run this Cloud Build Job any time a file in the --dir
changes. So we setup this trigger once:
# .cicd/triggers/meta-trigger.trigger.yaml
name: meta-trigger
description: "Trigger to apply Triggers on change"
github:
owner: <org/user_name>
name: <repo_name>
push:
branch: master
filename: .cicd/apply-triggers.cloudbuild.yaml
includedFiles:
- .cicd/**
For security purposes, I would suggest only running this trigger on pushes to master
so that changes must be approved before they are applied.
NB: this will perform a
gcloud beta builds triggers import --source=""
of Trigger configs that do not change.
🚨 Trigger includedFiles
uses Go Regex with additions, whereas the regex used by meta-triggers is Grep -E Perl regex. Take care.
Contributions of any kind are welcome! Feel free to tackle something from the todo list below.
run-meta-triggers.trigger.yaml
includedFiles regex to include any file in the repo that matches the *.trigger.(json|yaml)
regex.gcloud builds submit ./meta-cloud-builder/test/ --config=./meta-cloud-builder/test/cloudbuild.yaml
gcloud builds submit ./meta-triggers/test/ --config=./meta-triggers/test/cloudbuild.yaml