Dockerfile.py now live prints docker build output

Signed-off-by: Adam Hill <adam@diginc.us>
This commit is contained in:
Adam Hill 2019-09-17 23:06:24 -05:00
parent a6e70b653d
commit aa31e6baf6
No known key found for this signature in database
GPG Key ID: 2193804FCA429855
1 changed files with 7 additions and 10 deletions

View File

@ -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__':