mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
The build output is only added during failures, but its useful to
have this available during normal task execution as well.
(cherry picked from commit 33b8d1c57e
)
Co-authored-by: Raghu Siddarth Udiyar <raghusiddarth@gmail.com>
This commit is contained in:
parent
85fd4240f6
commit
51a3594494
3 changed files with 24 additions and 5 deletions
2
changelogs/fragments/805-docker_image-build-output.yml
Normal file
2
changelogs/fragments/805-docker_image-build-output.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
minor_changes:
|
||||
- "docker_image - return docker build output (https://github.com/ansible-collections/community.general/pull/805)."
|
|
@ -400,6 +400,12 @@ image:
|
|||
returned: success
|
||||
type: dict
|
||||
sample: {}
|
||||
stdout:
|
||||
description: Docker build output when building an image.
|
||||
returned: success
|
||||
type: str
|
||||
sample: ""
|
||||
version_added: 1.3.0
|
||||
'''
|
||||
|
||||
import errno
|
||||
|
@ -506,7 +512,8 @@ class ImageManager(DockerBaseClass):
|
|||
self.results['actions'].append("Built image %s from %s" % (image_name, self.build_path))
|
||||
self.results['changed'] = True
|
||||
if not self.check_mode:
|
||||
self.results['image'] = self.build_image()
|
||||
self.results.update(self.build_image())
|
||||
|
||||
elif self.source == 'load':
|
||||
# Load the image from an archive
|
||||
if not os.path.isfile(self.load_path):
|
||||
|
@ -713,7 +720,7 @@ class ImageManager(DockerBaseClass):
|
|||
)
|
||||
if self.client.docker_py_version < LooseVersion('3.0.0'):
|
||||
params['stream'] = True
|
||||
build_output = []
|
||||
|
||||
if self.tag:
|
||||
params['tag'] = "%s:%s" % (self.name, self.tag)
|
||||
if self.container_limits:
|
||||
|
@ -737,11 +744,14 @@ class ImageManager(DockerBaseClass):
|
|||
if self.target:
|
||||
params['target'] = self.target
|
||||
|
||||
build_output = []
|
||||
for line in self.client.build(**params):
|
||||
# line = json.loads(line)
|
||||
self.log(line, pretty_print=True)
|
||||
if "stream" in line:
|
||||
build_output.append(line["stream"])
|
||||
if "stream" in line or "status" in line:
|
||||
build_line = line.get("stream") or line.get("status")
|
||||
build_output.append(build_line)
|
||||
|
||||
if line.get('error'):
|
||||
if line.get('errorDetail'):
|
||||
errorDetail = line.get('errorDetail')
|
||||
|
@ -754,7 +764,9 @@ class ImageManager(DockerBaseClass):
|
|||
else:
|
||||
self.fail("Error building %s - message: %s, logs: %s" % (
|
||||
self.name, line.get('error'), build_output))
|
||||
return self.client.find_image(name=self.name, tag=self.tag)
|
||||
|
||||
return {"stdout": "\n".join(build_output),
|
||||
"image": self.client.find_image(name=self.name, tag=self.tag)}
|
||||
|
||||
def load_image(self):
|
||||
'''
|
||||
|
|
|
@ -136,6 +136,11 @@
|
|||
- repository_1 is changed
|
||||
- repository_2 is not changed
|
||||
|
||||
# Uncomment in community.docker
|
||||
# - assert:
|
||||
# that:
|
||||
# - 'FROM busybox' in repository_1.stdout
|
||||
|
||||
- name: Get facts of image
|
||||
docker_image_info:
|
||||
name: "{{ test_image_base }}:latest"
|
||||
|
|
Loading…
Reference in a new issue