Improve logging of docker calls

This commit is contained in:
Joe Rickerby
2020-03-14 17:21:47 +00:00
parent dc5dbea4c9
commit 7316d69139
+28 -19
View File
@@ -13,6 +13,13 @@ from .util import (
) )
def call(args, input=None, universal_newlines=False):
print('+ ' + ' '.join(shlex.quote(a) for a in args))
subprocess.run(
args, input=input, universal_newlines=universal_newlines, check=True
)
def matches_platform(identifier): def matches_platform(identifier):
pm = platform.machine() pm = platform.machine()
if pm == "x86_64": if pm == "x86_64":
@@ -95,19 +102,19 @@ def build(project_dir, output_dir, test_command, before_test, test_requires, tes
container_name = 'cibuildwheel-{}'.format(uuid.uuid4()) container_name = 'cibuildwheel-{}'.format(uuid.uuid4())
try: try:
subprocess.run(['docker', 'create', call(['docker', 'create',
'--env', 'CIBUILDWHEEL', '--env', 'CIBUILDWHEEL',
'--name', container_name, '--name', container_name,
'-i', '-i',
'-v', '/:/host', # ignored on CircleCI '-v', '/:/host', # ignored on CircleCI
docker_image, docker_image,
'/bin/bash'], check=True) '/bin/bash'])
subprocess.run(['docker', 'cp', call(['docker', 'cp',
os.path.abspath(project_dir) + '/.', os.path.abspath(project_dir) + '/.',
container_name + ':/project'], check=True) container_name + ':/project'])
subprocess.run(['docker', 'start', container_name], check=True) call(['docker', 'start', container_name])
for config in platform_configs: for config in platform_configs:
if dependency_constraints: if dependency_constraints:
@@ -118,16 +125,18 @@ def build(project_dir, output_dir, test_command, before_test, test_requires, tes
# mounted. https://github.com/moby/moby/issues/38995 # mounted. https://github.com/moby/moby/issues/38995
# Use `docker exec` instead. # Use `docker exec` instead.
with open(constraints_file, 'rb') as f: with open(constraints_file, 'rb') as f:
subprocess.run( call(
['docker', 'exec', container_name, 'sh', '-c', 'cat > /constraints.txt'], ['docker', 'exec', container_name, 'sh', '-c', 'cat > /constraints.txt'],
input=f.read(), input=f.read(),
) )
subprocess.run( call(
['docker', 'exec', '-i', container_name, '/bin/bash'], ['docker', 'exec', '-i', container_name, '/bin/bash'],
universal_newlines=True, universal_newlines=True,
check=True,
input=''' input='''
# give xtrace output an extra level of indent inside docker
PS4=' + '
set -o errexit set -o errexit
set -o xtrace set -o xtrace
mkdir -p /output mkdir -p /output
@@ -247,18 +256,18 @@ def build(project_dir, output_dir, test_command, before_test, test_requires, tes
) )
# copy the output back into the host # copy the output back into the host
subprocess.run(['docker', 'cp', call(['docker', 'cp',
container_name + ':/output/.', container_name + ':/output/.',
os.path.abspath(output_dir)], check=True) os.path.abspath(output_dir)])
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
exit(1) exit(1)
finally: finally:
# Still gets executed, even when 'exit(1)' gets called # Still gets executed, even when 'exit(1)' gets called
subprocess.run(['docker', 'rm', '--force', '-v', container_name], check=True) call(['docker', 'rm', '--force', '-v', container_name])
def troubleshoot(project_dir, error): def troubleshoot(project_dir, error):
if (isinstance(error, subprocess.CalledProcessError) and 'start' in error.cmd): if (isinstance(error, subprocess.CalledProcessError) and 'exec' in error.cmd):
# the bash script failed # the bash script failed
print('Checking for common errors...') print('Checking for common errors...')
so_files = [] so_files = []