Harbor's built-in GC feature does not support deleting images based on specific tags. This tool was created to clean up unnecessary tags, such as those containing "rc", "hotfix", and others.
- Clone the repository:
git pull https://github.com/warnerchen/harbor-cleaner.git- Set the required environment variables:
export HARBOR_REGISTRY=https://harbor.warnerchen.com
export HARBOR_USERNAME=harbor-cleaner
export HARBOR_PASSWORD=xxxxxx
export HARBOR_PROJECTS=library,rancherHARBOR_REGISTRY: Your Harbor registry URL.HARBOR_USERNAME: Username for authentication.HARBOR_PASSWORD: Password for authentication.HARBOR_PROJECTS: Comma-separated list of Harbor projects to clean.HARBOR_TAGS: This uses a fuzzy match, so any tag containing the specified strings will be deleted (e.g., "rc" will match "rc1-xxx", "v2.10.1-rc2", etc.)
- Navigate to the cloned repository and run the tool:
cd harbor-cleaner
go build -o harbor-cleaner main.go
./harbor-cleaner- Build the image:
docker build -t <registry>/library/harbor-cleaner:latest . -f deploy/Dockerfile
docker push <registry>/library/harbor-cleaner:latest- Deploy:
# Replace the values in deploy/configmap.yaml with your own values.
kubectl apply -f deploy/configmap.yaml
# Replace the values in deploy/secret.yaml with your own values.
kubectl apply -f deploy/secret.yaml
# Replace the image in deploy/cronjob.yaml with your image name.
kubectl apply -f deploy/cronjob.yaml