Skip to content

Commit

Permalink
Fix transports issues in podman_image
Browse files Browse the repository at this point in the history
Fix #218 #205 #264
Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
  • Loading branch information
sshnaidm committed Aug 8, 2023
1 parent aeec6b9 commit 7f22e15
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions plugins/modules/podman_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,19 +711,12 @@ def push_image(self):
# Build the destination argument
dest = self.push_args.get('dest')
dest_format_string = '{dest}/{image_name}'
regexp = re.compile(r'/{name}(:{tag})?'.format(name=self.name, tag=self.tag))
if not dest:
if '/' not in self.name:
self.module.fail_json(msg="'push_args['dest']' is required when pushing images that do not have the remote registry in the image name")

# If the push destination contains the image name and/or the tag
# remove it and warn since it's not needed.
elif regexp.search(dest):
dest = regexp.sub('', dest)
self.module.warn("Image name and tag are automatically added to push_args['dest']. Destination changed to {dest}".format(dest=dest))

if dest and dest.endswith('/'):
dest = dest[:-1]
if dest:
dest = dest.rstrip('/')

transport = self.push_args.get('transport')
if transport:
Expand All @@ -736,19 +729,20 @@ def push_image(self):
else:
dest_format_string = '{transport}:{dest}'

dest_string = dest_format_string.format(transport=transport, name=self.name, dest=dest, image_name=self.image_name,)
dest_string = dest_format_string.format(transport=transport, name=self.name, dest=dest, image_name=self.image_name,)
else:
if len(dest.split('/')) < 3:
dest_string = f'{dest}/{self.image_name}'
else:
dest_string = dest

# Only append the destination argument if the image name is not a URL
if '/' not in self.name:
args.append(dest_string)
args.append(dest_string)
self.module.log("PODMAN-IMAGE-DEBUG: Pushing image {image_name} to {dest_string}".format(image_name=self.image_name, dest_string=dest_string))

rc, out, err = self._run(args, ignore_errors=True)
if rc != 0:
self.module.fail_json(msg="Failed to push image {image_name}: {err}".format(image_name=self.image_name, err=err))
last_id = self._get_id_from_output(
out + err, contains=':', split_on=':')

return self.inspect_image(last_id), out + err
return self.inspect_image(self.image_name), out + err

def remove_image(self, image_name=None):
if image_name is None:
Expand Down

0 comments on commit 7f22e15

Please sign in to comment.