I have automatic builds set up in Google Cloud, so that each time I push to the master branch of my repository, a new image is built and pushed to Google Container Registry.
These images pile up quickly, and I don't need all the old ones. So I would like to add a build step that runs a bash script which calls gcloud container images list-tags
, loops the results, and deletes the old ones with gcloud container images delete
.
I have the script written and it works locally. I am having trouble figuring out how to run it as a step in Cloud Builder.
It seems there are 2 options:
- name: 'ubuntu'
args: ['bash', './container-registry-cleanup.sh']
In the above step in cloudbuild.yml
I try to run the bash
command in the ubuntu
image. This doesn't work because the gcloud
command does not exist in this image.
- name: 'gcr.io/cloud-builders/gcloud'
args: [what goes here???]
In the above step in cloudbuild.yml
I try to use the gcloud
image, but since "Arguments passed to this builder will be passed to gcloud
directly", I don't know how to call my bash script here.
What can I do?