Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated cleanup of images built by integration tests in our GCP project #1099

Open
chanseokoh opened this issue Oct 4, 2018 · 2 comments

Comments

@chanseokoh
Copy link
Member

chanseokoh commented Oct 4, 2018

The GCR of our integration testing project has accumulated thousands of images. I am cleaning them, but we will continue to accumulate them.

To list all the immediate "sub-repositories":

gcloud container images list --repository="gcr.io/${GCP_PROJECT}"

To delete all tags of a repository (not tested and may not work):

NAME="gcr.io/${GCP_PROJECT}/simpleimage"
gcloud container images list-tags "${NAME}" --format='get(digest)' \
  | sed -e "s,^,${NAME}@," \
  | xargs gcloud container images delete --quiet --force-delete-tags

FTR:

#!/bin/sh

GCP_PROJECT="${1:-jib-integration-testing}"

delete_images() { 
  echo "* Deleting images in ${1}..."

  local tags=$( gcloud container images list-tags "${1}" --format='get(digest)' \
    | sed -e "s,^,${1}@," )
  if [ -n "${tags}" ]; then
    gcloud container images delete --quiet --force-delete-tags $tags
  else
    echo "no tags to delete"
  fi
}

delete_repository() {
  local repositories=$( gcloud container images list --repository="${1}" )
  for repo in ${repositories}; do
    if [ "${repo}" != "NAME" ]; then
      ( delete_repository "${repo}" )
      delete_images "${repo}"
    fi
  done
}

delete_repository "gcr.io/${GCP_PROJECT}"
@loosebazooka
Copy link
Member

@chanseokoh should we do some sort of weekly cron cleanup at 2am on sunday?

@chanseokoh
Copy link
Member Author

Yeah, we can do this. The question is, where to implement this cron. I've been doing this occasionally on my machine.

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

No branches or pull requests

2 participants