Skip to content

Commit 276e8be

Browse files
committed
tag search fixes
1 parent be19be3 commit 276e8be

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

registry.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,20 +132,34 @@ def main(pull_gitlab_url, pull_project_path, push_gitlab_url, push_project_path,
132132
image = docker_client.images.get(image_id)
133133
print(f"Pushing image: {image.id}.")
134134

135+
# We need to work with a tag that contains old_registry_location
136+
# If the image has no tags, skip it.
137+
if not image.tags:
138+
print(f" Image {image.id} has no tags, skipping.")
139+
continue
140+
141+
# Find tag number that contains old_registry_location.
142+
tag_number = 0
143+
for tag in image.tags:
144+
if old_registry_location in tag:
145+
print(f" Found tag {tag} with old registry location {old_registry_location}.")
146+
break
147+
tag_number += 1
148+
135149
# If the image tag contains two colons, it means it has a port specified.
136-
if ':' in image.tags[0] and image.tags[0].count(':') > 1:
137-
image_tag = image.tags[0].split(':')[2]
138-
image_without_tag = image.tags[0].split(':')[0] + ":" + image.tags[0].split(':')[1]
150+
if ':' in image.tags[tag_number] and image.tags[tag_number].count(':') > 1:
151+
image_tag = image.tags[tag_number].split(':')[2]
152+
image_without_tag = image.tags[tag_number].split(':')[0] + ":" + image.tags[tag_number].split(':')[1]
139153
# If the image tag contains one colon, it means the port is not specified, and the tag is after the first colon.
140-
elif ':' in image.tags[0] and image.tags[0].count(':') == 1:
141-
image_tag = image.tags[0].split(':')[1]
142-
image_without_tag = image.tags[0].split(':')[0]
154+
elif ':' in image.tags[tag_number] and image.tags[tag_number].count(':') == 1:
155+
image_tag = image.tags[tag_number].split(':')[1]
156+
image_without_tag = image.tags[tag_number].split(':')[0]
143157
# In other cases just use skip this image.
144158
else:
145159
print(f" Image {image.id} has no repository specific tag, skipping.")
146160
continue
147161

148-
print(f" Image {image.id} has repository specific tag: {image.tags[0]} and tag: {image_tag}.")
162+
print(f" Image {image.id} has repository specific tag: {image.tags[tag_number]} and tag: {image_tag}.")
149163

150164
# Remove old_registry_location from the image_without_tag - it will give repository path inside project registry.
151165
repository_path = image_without_tag.replace(old_registry_location, '')

0 commit comments

Comments
 (0)