Fix image tag operation. Allows repository in form of repo:tag. If no tag value, defaults to 'latest'.
This commit is contained in:
parent
95a7ee271a
commit
c27054090a
1 changed files with 11 additions and 7 deletions
|
@ -91,7 +91,8 @@ options:
|
|||
required: false
|
||||
repository:
|
||||
description:
|
||||
- Full path to a repository. Use with state C(present) to tag the image into the repository.
|
||||
- Full path to a repository. Use with state C(present) to tag the image into the repository. Expects
|
||||
format I(repository:tag). If no tag is provided, will default to 'latest'.
|
||||
required: false
|
||||
version_added: "2.1"
|
||||
state:
|
||||
|
@ -425,13 +426,16 @@ class ImageManager(DockerBaseClass):
|
|||
:return: None
|
||||
'''
|
||||
repo, repo_tag = parse_repository_tag(repository)
|
||||
if not repo_tag:
|
||||
repo_tag = "latest"
|
||||
image = self.client.find_image(name=repo, tag=repo_tag)
|
||||
found = 'found' if image else 'not found'
|
||||
self.log("image %s was %s" % (repo, found))
|
||||
|
||||
if not image or force:
|
||||
self.log("tagging %s:%s to %s" % (name, tag, repository))
|
||||
self.log("tagging %s:%s to %s:%s" % (name, tag, repo, repo_tag))
|
||||
self.results['changed'] = True
|
||||
self.results['actions'].append("Tagged image %s:%s to %s" % (name, tag, repository))
|
||||
self.results['actions'].append("Tagged image %s:%s to %s:%s" % (name, tag, repo, repo_tag))
|
||||
if not self.check_mode:
|
||||
try:
|
||||
# Finding the image does not always work, especially running a localhost registry. In those
|
||||
|
@ -439,14 +443,14 @@ class ImageManager(DockerBaseClass):
|
|||
image_name = name
|
||||
if tag and not re.search(tag, name):
|
||||
image_name = "%s:%s" % (name, tag)
|
||||
tag_status = self.client.tag(image_name, repository, tag=tag, force=True)
|
||||
tag_status = self.client.tag(image_name, repo, tag=repo_tag, force=True)
|
||||
if not tag_status:
|
||||
raise Exception("Tag operation failed.")
|
||||
except Exception as exc:
|
||||
self.fail("Error: failed to tag image %s - %s" % (name, str(exc)))
|
||||
self.results['image'] = self.client.find_image(name=repository, tag=tag)
|
||||
self.fail("Error: failed to tag image - %s" % str(exc))
|
||||
self.results['image'] = self.client.find_image(name=repo, tag=repo_tag)
|
||||
if push:
|
||||
self.push_image(repository, tag)
|
||||
self.push_image(repo, repo_tag)
|
||||
|
||||
def build_image(self):
|
||||
'''
|
||||
|
|
Loading…
Reference in a new issue