mirror of
https://github.com/ansible-collections/community.docker.git
synced 2026-04-03 10:14:13 +00:00
Refactor docker_image line extraction code. (#62)
This commit is contained in:
parent
a11f24c3a9
commit
2a0fb7d3ed
@ -598,6 +598,17 @@ class ImageManager(DockerBaseClass):
|
|||||||
if push:
|
if push:
|
||||||
self.push_image(repo, repo_tag)
|
self.push_image(repo, repo_tag)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _extract_output_line(line, output):
|
||||||
|
'''
|
||||||
|
Extract text line from stream output and, if found, adds it to output.
|
||||||
|
'''
|
||||||
|
if 'stream' in line or 'status' in line:
|
||||||
|
# Make sure we have a string (assuming that line['stream'] and
|
||||||
|
# line['status'] are either not defined, falsish, or a string)
|
||||||
|
text_line = line.get('stream') or line.get('status') or ''
|
||||||
|
output.append(text_line)
|
||||||
|
|
||||||
def build_image(self):
|
def build_image(self):
|
||||||
'''
|
'''
|
||||||
Build an image
|
Build an image
|
||||||
@ -647,9 +658,7 @@ class ImageManager(DockerBaseClass):
|
|||||||
for line in self.client.build(**params):
|
for line in self.client.build(**params):
|
||||||
# line = json.loads(line)
|
# line = json.loads(line)
|
||||||
self.log(line, pretty_print=True)
|
self.log(line, pretty_print=True)
|
||||||
if "stream" in line or "status" in line:
|
self._extract_output_line(line, build_output)
|
||||||
build_line = line.get("stream") or line.get("status") or ''
|
|
||||||
build_output.append(build_line)
|
|
||||||
|
|
||||||
if line.get('error'):
|
if line.get('error'):
|
||||||
if line.get('errorDetail'):
|
if line.get('errorDetail'):
|
||||||
@ -681,9 +690,7 @@ class ImageManager(DockerBaseClass):
|
|||||||
self.log("Loading image from %s" % self.load_path)
|
self.log("Loading image from %s" % self.load_path)
|
||||||
for line in self.client.load_image(image_tar):
|
for line in self.client.load_image(image_tar):
|
||||||
self.log(line, pretty_print=True)
|
self.log(line, pretty_print=True)
|
||||||
if "stream" in line or "status" in line:
|
self._extract_output_line(line, load_output)
|
||||||
load_line = line.get("stream") or line.get("status") or ''
|
|
||||||
load_output.append(load_line)
|
|
||||||
except EnvironmentError as exc:
|
except EnvironmentError as exc:
|
||||||
if exc.errno == errno.ENOENT:
|
if exc.errno == errno.ENOENT:
|
||||||
self.client.fail("Error opening image %s - %s" % (self.load_path, str(exc)))
|
self.client.fail("Error opening image %s - %s" % (self.load_path, str(exc)))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user