registry-cli icon indicating copy to clipboard operation
registry-cli copied to clipboard

Always removes the 5 latest instead of keeping the 5 latest

Open warhansen opened this issue 6 years ago • 9 comments

Hi, awesome tool!

However, when I run the command it deletes the latest 5 images, instead of keeping the 5 latest:

Getting digests for tags to keep: Getting digest for tag latest Keep digest sha256:28d2f0b496b3f88631ac9e00ddf03254ab53d97e513bdd75636afc02096fcfa1 for tag latest

Image: rla-dataloader tag: RLA2-05022019 tag: RLA2-29012019 tag: RLA2-25012019 tag: RLA2-31012019 tag: RLA2-28012019 tag: RLA2-30012019 Getting digests for tags to keep: Getting digest for tag RLA2-29012019 Keep digest sha256:eb60f90f93fd44377dbac8f64754ac9585d9ab7d5fe754867e433d54491ee47b for tag RLA2-29012019 Getting digest for tag RLA2-25012019 Keep digest sha256:8f5c534bb26c8e2e7052a1d052579ffb47ab87265591ea1f962543f083d179b1 for tag RLA2-25012019 Getting digest for tag RLA2-31012019 Keep digest sha256:212608523c2421fe603b3d307c14053c05faffd645372abcbd6645cb1f6e68a5 for tag RLA2-31012019 Getting digest for tag RLA2-28012019 Keep digest sha256:e8082323a083e1a7071da43c4d14155c79673b0823905a48d6eebbb3ce8fd762 for tag RLA2-28012019 Getting digest for tag RLA2-30012019 Keep digest sha256:b7f1fd6965b10bffc69f09978369a4f2b51764d1b226ba36fedeffc17fd64357 for tag RLA2-30012019 deleting tag RLA2-05022019 done

Image: rla-liberty tag: RLA2-05022019 tag: RLA2-29012019 tag: RLA2-25012019 tag: RLA2-31012019 tag: RLA2-28012019 tag: RLA2-30012019 Getting digests for tags to keep: Getting digest for tag RLA2-29012019 Keep digest sha256:f547fc7673e821001903dc12e53de73a985b3e7cfd51fb4de0d3ca005f41774a for tag RLA2-29012019 Getting digest for tag RLA2-25012019 Keep digest sha256:eec92b33d767131d3bc4e42df2978c04774d3de7df935aa37dac8f012b37f66d for tag RLA2-25012019 Getting digest for tag RLA2-31012019 Keep digest sha256:bdbf761f19e876d9cbfa30df77375cfb0be6af1fae68fd88550a8a58cf7d42b9 for tag RLA2-31012019 Getting digest for tag RLA2-28012019 Keep digest sha256:027b5ee15315372f8974cb31762725f6c68ba81e6fa26b79ed2c988fcfabec47 for tag RLA2-28012019 Getting digest for tag RLA2-30012019 Keep digest sha256:d00265c006f1a4dd991f8341c226f1e5184da6f6f9c947ad90029598c55f5693 for tag RLA2-30012019 deleting tag RLA2-05022019 done

Image: rla-test-automation-pack tag: latest Getting digests for tags to keep: Getting digest for tag latest

Obviously I tag per date so you can see it is REMOVING the latest image! (deleting tag RLA2-05022019 done)

This is the command I am running:

python docker-registry/registry.py -l docker:docker -r https://dockerhub.myrepo.local --no-validate-ssl --delete --num 5 Thanks

warhansen avatar Feb 05 '19 13:02 warhansen

So it turns out the inside a month it works fine, but when a new month starts it keeps on deleting the newest ones for the new month, instead of deleting the older ones of the previous month

warhansen avatar Mar 01 '19 08:03 warhansen

@warhansen it happens because the default algorithm for sort image names is human sorting.

alist.sort(key=natural_keys) sorts in human order http://nedbatchelder.com/blog/200712/human_sorting.html (See Toothy's implementation in the comments)

If you want to delete images by their date you can try to use the argument --delete-by-hours

ipavlushin avatar Mar 01 '19 17:03 ipavlushin

Ok, however there are older images that will be much older than the hours specified in some of the other repositories of which there are only 1 image, and they will also then get deleted!

warhansen avatar Mar 04 '19 06:03 warhansen

Yes, you are right. There is no possibility to use --num with --delete-by-hours for that.

ipavlushin avatar Mar 04 '19 09:03 ipavlushin

I hit the same issue and found an option --order-by-date With this option, it will sort tags by date instead of names

olfway avatar Aug 07 '19 12:08 olfway

@olfway looks like the option suggested by you is not recognized. How did you invoke it ?

+ docker run --rm anoxis/registry-cli -r http://***************** --delete --num 5 --order-by-date
usage: registry.py [-h] [-l USER:PASSWORD] [-w] -r URL [-d] [-n [N]] [--debug]
                   [--dry-run] [-i IMAGE:[TAG] [IMAGE:[TAG] ...]]
                   [--images-like IMAGES_LIKE [IMAGES_LIKE ...]]
                   [--keep-tags KEEP_TAGS [KEEP_TAGS ...]]
                   [--tags-like TAGS_LIKE [TAGS_LIKE ...]]
                   [--keep-tags-like KEEP_TAGS_LIKE [KEEP_TAGS_LIKE ...]]
                   [--no-validate-ssl] [--delete-all] [--layers]
                   [--delete-by-hours [Hours]] [--keep-by-hours [Hours]]
                   [--digest-method HEAD|GET] [--auth-method POST|GET]
registry.py: error: unrecognized arguments: --order-by-date

Constantin07 avatar Aug 07 '19 19:08 Constantin07

It was added 10 days ago https://github.com/andrey-pohilko/registry-cli/commit/422ab543022ef966579e45d48e3c8a0125de0c27

and docker image on docker hub is outdated

olfway avatar Aug 07 '19 19:08 olfway

Thanks @olfway for sharing. Voted for docker image update.

Constantin07 avatar Aug 08 '19 18:08 Constantin07

the docker image was updated. please check if you see this option now

andrey-pohilko avatar Aug 13 '19 05:08 andrey-pohilko