devopshq / devopshq/artifactory-cleanup
Formatting Question - Possible Bug
- Dominant language
- Python
- Stars
- 160
- Forks
- 87
- PR merge metrics
- No merged PRs in 30d
Description
We have docker images tagged with numerous tag patterns. Examples:
- v1
- v1.2
- v1.2.3
- v1.2.3.4
- 1
- 1.2
- 1.2.3
- 1.2.3.4
- 1.2.3_2023-14
- v1.2.3_2023-14
I attempted to configure a rule as follows:
```
- rule: KeepLatestNVersionImagesByProperty
count: 2
custom_regexp: "(^v?(\\d+)+(\\.\\d+)*|(_\\d{4}\\-\\d{2})*$)"
```
In my regex tester, all tags match. However, when running this in artifactory-cleanup I get this error:
```
Filter artifacts - rule: KeepLatestNVersionImagesByProperty - Leaves ``count`` Docker images with the same major.
artifacts = rule.filter(artifacts)
File "/usr/local/lib/python3.9/site-packages/artifactory_cleanup/rules/docker.py", line 238, in filter
grouped = pydash.group_by(artifacts, iteratee=_groupby)
File "/usr/local/lib/python3.9/site-packages/pydash/collections.py", line 397, in group_by
key = cbk(value)
File "/usr/local/lib/python3.9/site-packages/artifactory_cleanup/rules/docker.py", line 234, in _groupby
self.get_version(artifact)[: self.number_of_digits_in_version],
File "/usr/local/lib/python3.9/site-packages/artifactory_cleanup/rules/docker.py", line 224, in get_version
version = tuple(map(int, version_str.split(".")))
ValueError: invalid literal for int() with base 10: 'v1'
```
Tags with a preceding 'v' in the tag fail. Is my RegEx incorrect (if so, what would be correct?) or is this a bug in the code?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in artifactory_cleanup/rules/docker.py at get_version around line 224 and the _groupby call in filter around line 234, then reproduce the failure with tags beginning with v. Check how custom_regexp results are passed into version parsing. Done means the documented tag patterns, including v-prefixed tags, are handled without the shown ValueError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, python
- Domain
- devops, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100