In Google Container Registry, I made a tool to delete images by parallelizing them appropriately.
https://github.com/h-r-k-matsumoto/gcr-garbage-collect
When I want to erase unnecessary images without tags in Google Container Registry for mental health, I do it from the console screen.
If you do 10 or more at once, it will almost certainly be as follows ** Could not delete one or more selected images. ** ** Is displayed and some deletions fail.
Then, if you execute the following from the shell, you can delete it stably, but it takes about 5 seconds to delete one image, ** It is extremely slow. ** **
# get image list
gcloud container images list-tags asia.gcr.io/{project-id}/${image-name} --filter="NOT tags:* AND timestamp.datetime < '2018-06-01'"
# delete image
gcloud container images delete asia.gcr.io/{project-id}/${image-name}@sha256:{digest} --force-delete-tags --quiet
Then you can parallelize and delete it! That's why I made a tool.
https://github.com/h-r-k-matsumoto/gcr-garbage-collect
** Confirmation of deletion target **
$ java -jar gcr-garbage-collect-0.0.1-SNAPSHOT.jar --dry-run=true
** Delete execution **
$ java -jar gcr-garbage-collect-0.0.1-SNAPSHOT.jar --dry-run=false
** Delete only specific images **
java -jar gcr-garbage-collect-0.0.1-SNAPSHOT.jar --gcloud.container.image=asia.gcr.io/{gcp-project-id}/{image-name}
** Change the number of parallels **
$ java -jar gcr-garbage-collect-0.0.1-SNAPSHOT.jar --parallelism=16
--I haven't seen the API for the container registry in Google Docs ... Since there is no help for it, I am using gcloud direct execution format.
--In the windows environment, application.yaml or as a runtime argument
--gcloud.command =" C: / Program Files (x86) /Google/Cloud SDK/google-cloud-sdk/bin/gcloud.cmd Please specify "
etc.
――I've used ProcessBuilder for a long time, but it doesn't absorb <
and "
depending on each OS.
――I wanted to make it a docker image, but I stopped because it was troublesome around gcloud authentication.
――I wondered how fast it was, but I decided to compare it, but I stopped because I didn't plan the speed in the first place.
--I'm deleting it because of mental health problems only. Even if the old one remains, it doesn't hurt much. (GCS charges aren't too much to worry about)
Recommended Posts