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

Always removes the 5 latest instead of keeping the 5 latest #64

Open
warhansen opened this issue Feb 5, 2019 · 9 comments
Open

Always removes the 5 latest instead of keeping the 5 latest #64

warhansen opened this issue Feb 5, 2019 · 9 comments

Comments

@warhansen
Copy link

warhansen commented Feb 5, 2019

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
Copy link
Author

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

@ipavlushin
Copy link
Collaborator

@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

@warhansen
Copy link
Author

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!

@ipavlushin
Copy link
Collaborator

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

@olfway
Copy link

olfway commented Aug 7, 2019

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

@Constantin07
Copy link

@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

@olfway
Copy link

olfway commented Aug 7, 2019

It was added 10 days ago
422ab54

and docker image on docker hub is outdated

@Constantin07
Copy link

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

@andrey-pohilko
Copy link
Owner

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

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

No branches or pull requests

5 participants