Skip to content

Commit

Permalink
Merge pull request #47 from phenixblue/issue-46-fix
Browse files Browse the repository at this point in the history
Add fix for dotted tag on library image
  • Loading branch information
phenixblue authored Aug 1, 2021
2 parents 293244d + 1271e46 commit 89241b3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/imageswap/imageswap.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def swap_image(container_spec):
library_image = False

# Check if first section is a Registry URL
if "." in image_split[0]:
if "." in image_split[0] and image_split[1] != "" and image_split[2] != "":
image_registry = image_split[0]
else:
# Set docker.io if no registry is detected
Expand Down
16 changes: 16 additions & 0 deletions app/imageswap/test/test_image_map_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,22 @@ def test_map_config_with_library_image(self):
self.assertTrue(result)
self.assertEqual(container_spec["image"], expected_image)

def test_map_config_with_library_image_with_dotted_tag(self):

"""Method to test Map File config (map with library registry and a tag that contains a ".")"""

imageswap.imageswap_maps_file = "./testing/map_files/map_file_library_image.conf"

container_spec = {}
container_spec["name"] = "test-container"
container_spec["image"] = "rabbitmq:3.8.18-management"

expected_image = "harbor.example.com/library/rabbitmq:3.8.18-management"
result = imageswap.swap_image(container_spec)

self.assertTrue(result)
self.assertEqual(container_spec["image"], expected_image)


if __name__ == "__main__":
unittest.main()
14 changes: 14 additions & 0 deletions app/imageswap/test/test_image_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,20 @@ def test_image_format_project_image_digest(self):
self.assertTrue(result)
self.assertEqual(container_spec["image"], expected_image)

def test_image_format_library_image_with_dotted_tag(self):

"""Method to test MAP based swap (library image with tag that contains a ".": \"rabbitmq:3.8.18-management\")"""

container_spec = {}
container_spec["name"] = "test-container"
container_spec["image"] = "rabbitmq:3.8.18-management"

expected_image = "my.example.com/mirror-docker.io/rabbitmq:3.8.18-management"
result = imageswap.swap_image(container_spec)

self.assertTrue(result)
self.assertEqual(container_spec["image"], expected_image)


if __name__ == "__main__":
unittest.main()

0 comments on commit 89241b3

Please sign in to comment.