GoogleContainerTools / GoogleContainerTools/jib

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

Open
#1,099 2 comments 0 reactions 0 assignees View on GitHub
area/jib-cli area/jib-core area/jib-gradle-plugin area/jib-maven-plugin cleanup priority:p3
Dominant language
Java
Stars
14.5k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

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":
```sh
gcloud container images list --repository="gcr.io/${GCP_PROJECT}"
```

To delete all tags of a repository (not tested and may not work):
```sh
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:

```sh
#!/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}"
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.