Merge pull request #4339 from chouseknecht/fix_4235

Fix image tag operation
reviewable/pr18780/r1
Chris Houseknecht 8 years ago committed by GitHub
commit 85ed6f488b

@ -91,7 +91,8 @@ options:
required: false required: false
repository: repository:
description: 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 required: false
version_added: "2.1" version_added: "2.1"
state: state:
@ -425,13 +426,16 @@ class ImageManager(DockerBaseClass):
:return: None :return: None
''' '''
repo, repo_tag = parse_repository_tag(repository) repo, repo_tag = parse_repository_tag(repository)
if not repo_tag:
repo_tag = "latest"
image = self.client.find_image(name=repo, tag=repo_tag) image = self.client.find_image(name=repo, tag=repo_tag)
found = 'found' if image else 'not found' found = 'found' if image else 'not found'
self.log("image %s was %s" % (repo, found)) self.log("image %s was %s" % (repo, found))
if not image or force: 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['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: if not self.check_mode:
try: try:
# Finding the image does not always work, especially running a localhost registry. In those # Finding the image does not always work, especially running a localhost registry. In those
@ -439,14 +443,14 @@ class ImageManager(DockerBaseClass):
image_name = name image_name = name
if tag and not re.search(tag, name): if tag and not re.search(tag, name):
image_name = "%s:%s" % (name, tag) 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: if not tag_status:
raise Exception("Tag operation failed.") raise Exception("Tag operation failed.")
except Exception as exc: except Exception as exc:
self.fail("Error: failed to tag image %s - %s" % (name, str(exc))) self.fail("Error: failed to tag image - %s" % str(exc))
self.results['image'] = self.client.find_image(name=repository, tag=tag) self.results['image'] = self.client.find_image(name=repo, tag=repo_tag)
if push: if push:
self.push_image(repository, tag) self.push_image(repo, repo_tag)
def build_image(self): def build_image(self):
''' '''

Loading…
Cancel
Save