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

Fix: manifest_to_docker_images fails as path is not splittable #140

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions artifactory_cleanup/rules/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ def _manifest_to_docker_images(self, artifacts: ArtifactsList):
# already done it or it's just a folder
if "name" not in artifact or artifact["name"] != self.MANIFEST_FILENAME:
continue

artifact["path"], docker_tag = artifact["path"].rsplit("/", 1)
artifact["name"] = docker_tag
artifact["path"] = artifact["properties"]["docker.repoName"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how it's saved nowadays, and that all properties exists on all docker images - could you add a false back instead?
The logic would be this one - if rsplit returns two elements - we use old logic, if not - new one.
And please add two tests for that as well, so we know that it works as it used to with old artifacts too

artifact["name"] = artifact["properties"]["docker.manifest"]
# We're going to collect docker size later
if "size" in artifact:
del artifact["size"]
Expand Down
34 changes: 17 additions & 17 deletions tests/test_rules_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,67 +14,67 @@ def test_filter(self):

data = [
{
"properties": {"docker.manifest": "0.1.100"},
"properties": {"docker.manifest": "0.1.100", "docker.repoName": "foobar"},
"path": "foobar/0.1.100",
"name": "manifest.json",
},
{
"properties": {"docker.manifest": "0.1.200"},
"properties": {"docker.manifest": "0.1.200", "docker.repoName": "foobar"},
"path": "foobar/0.1.200",
"name": "manifest.json",
},
{
"properties": {"docker.manifest": "0.1.99"},
"properties": {"docker.manifest": "0.1.99", "docker.repoName": "foobar"},
"path": "foobar/0.1.99",
"name": "manifest.json",
},
{
"properties": {"docker.manifest": "1.1.1"},
"properties": {"docker.manifest": "1.1.1", "docker.repoName": "foobar"},
"path": "foobar/1.1.1",
"name": "manifest.json",
},
{
"properties": {"docker.manifest": "1.2.1"},
"properties": {"docker.manifest": "1.2.1", "docker.repoName": "foobar"},
"path": "foobar/1.2.1",
"name": "manifest.json",
},
{
"properties": {"docker.manifest": "1.3.1"},
"properties": {"docker.manifest": "1.3.1", "docker.repoName": "foobar"},
"path": "foobar/1.3.1",
"name": "manifest.json",
},
{
"properties": {"docker.manifest": "2.1.1"},
"properties": {"docker.manifest": "2.1.1", "docker.repoName": "foobar"},
"path": "foobar/2.1.1",
"name": "manifest.json",
},
{
"properties": {"docker.manifest": "0.1.86"},
"properties": {"docker.manifest": "0.1.86", "docker.repoName": "baz"},
"path": "baz/0.1.86",
"name": "manifest.json",
},
{
"properties": {"docker.manifest": "0.1.87"},
"properties": {"docker.manifest": "0.1.87", "docker.repoName": "baz"},
"path": "baz/0.1.87",
"name": "manifest.json",
},
{
"properties": {"docker.manifest": "0.1.83"},
"properties": {"docker.manifest": "0.1.83", "docker.repoName": "baz"},
"path": "baz/0.1.83",
"name": "manifest.json",
},
{
"properties": {"docker.manifest": "v0.1.100"},
"properties": {"docker.manifest": "v0.1.100", "docker.repoName": "qux"},
"path": "qux/v0.1.100",
"name": "manifest.json",
},
{
"properties": {"docker.manifest": "v0.1.200"},
"properties": {"docker.manifest": "v0.1.200", "docker.repoName": "qux"},
"path": "qux/v0.1.200",
"name": "manifest.json",
},
{
"properties": {"docker.manifest": "v0.1.99"},
"properties": {"docker.manifest": "v0.1.99", "docker.repoName": "qux"},
"path": "qux/v0.1.99",
"name": "manifest.json",
},
Expand All @@ -94,25 +94,25 @@ def test_filter(self):
{
"name": "0.1.83",
"path": "baz",
"properties": {"docker.manifest": "0.1.83"},
"properties": {"docker.manifest": "0.1.83", "docker.repoName": "baz"},
"stats": {},
},
{
"name": "0.1.99",
"path": "foobar",
"properties": {"docker.manifest": "0.1.99"},
"properties": {"docker.manifest": "0.1.99", "docker.repoName": "foobar"},
"stats": {},
},
{
"name": "1.1.1",
"path": "foobar",
"properties": {"docker.manifest": "1.1.1"},
"properties": {"docker.manifest": "1.1.1", "docker.repoName": "foobar"},
"stats": {},
},
{
"name" : "v0.1.99",
"path": "qux",
"properties": {"docker.manifest": "v0.1.99"},
"properties": {"docker.manifest": "v0.1.99", "docker.repoName": "qux"},
"stats": {},
},
]
Loading