From aa31e6baf6b4f812bc428148ce14fb9ff153f118 Mon Sep 17 00:00:00 2001 From: Adam Hill Date: Tue, 17 Sep 2019 23:06:24 -0500 Subject: [PATCH] Dockerfile.py now live prints docker build output Signed-off-by: Adam Hill --- Dockerfile.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/Dockerfile.py b/Dockerfile.py index 50ee06f..916b6c1 100755 --- a/Dockerfile.py +++ b/Dockerfile.py @@ -21,7 +21,8 @@ from docopt import docopt from jinja2 import Environment, FileSystemLoader from docopt import docopt import os -import testinfra +import subprocess +import sys THIS_DIR = os.path.dirname(os.path.abspath(__file__)) @@ -105,10 +106,6 @@ def build_dockerfiles(args): def build(docker_repo, arch, args): - run_local = testinfra.get_backend( - "local://" - ).get_module("Command").run - dockerfile = 'Dockerfile_{}'.format(arch) repo_tag = '{}:{}_{}'.format(docker_repo, __version__, arch) cached_image = '{}/{}'.format('pihole', repo_tag) @@ -123,14 +120,14 @@ def build(docker_repo, arch, args): print(" ::: Building {} into {}".format(dockerfile, repo_tag)) if args['-v']: print(build_command, '\n') - build_result = run_local(build_command) + build_result = subprocess.Popen(build_command.split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT) if args['-v']: - print(build_result.stdout) - print(build_result.stderr) - if build_result.rc != 0: + for c in iter(lambda: build_result.stdout.read(1), b''): # replace '' with b'' for Python 3 + sys.stdout.write(c) + if build_result.returncode != 0: print(" ::: Building {} encountered an error".format(dockerfile)) print(build_result.stderr) - assert build_result.rc == 0 + assert build_result.returncode == 0 if __name__ == '__main__':