Cleaning up use of run_docker and removing some debug output

This commit is contained in:
Yannick Jadoul
2018-09-09 16:11:42 +02:00
parent 4cc09a35b4
commit b64770a560
+17 -20
View File
@@ -67,12 +67,6 @@ def build(project_dir, package_name, output_dir, test_command, test_requires, be
PATH="$PYBIN:$PATH" sh -c {before_build} PATH="$PYBIN:$PATH" sh -c {before_build}
fi fi
pwd
ls -l .
ls -l /project
ls -l /output
ls -l /host
# Build that wheel # Build that wheel
PATH="$PYBIN:$PATH" "$PYBIN/pip" wheel . -w /tmp/built_wheel --no-deps {build_verbosity_flag} PATH="$PYBIN:$PATH" "$PYBIN/pip" wheel . -w /tmp/built_wheel --no-deps {build_verbosity_flag}
built_wheel=(/tmp/built_wheel/*.whl) built_wheel=(/tmp/built_wheel/*.whl)
@@ -126,7 +120,7 @@ def build(project_dir, package_name, output_dir, test_command, test_requires, be
def run_docker(command, stdin_str=None): def run_docker(command, stdin_str=None):
print('docker command: docker {}'.format(' '.join(map(shlex_quote, command)))) print('docker command: docker {}'.format(' '.join(map(shlex_quote, command))))
if stdin_str is None: if stdin_str is None:
return subprocess.check_call(['docker'] + command) subprocess.check_call(['docker'] + command)
else: else:
process = subprocess.Popen(['docker'] + command, process = subprocess.Popen(['docker'] + command,
stdin=subprocess.PIPE, universal_newlines=True) stdin=subprocess.PIPE, universal_newlines=True)
@@ -135,19 +129,22 @@ def build(project_dir, package_name, output_dir, test_command, test_requires, be
except KeyboardInterrupt: except KeyboardInterrupt:
process.kill() process.kill()
process.wait() process.wait()
return process.returncode if process.returncode != 0:
raise subprocess.CalledProcessError(process.returncode, process.args)
container_name = 'cibuildwheel-{}'.format(uuid.uuid4()) container_name = 'cibuildwheel-{}'.format(uuid.uuid4())
run_docker(['create', try:
'--env', 'CIBUILDWHEEL', run_docker(['create',
'--name', container_name, '--env', 'CIBUILDWHEEL',
'-i', '--name', container_name,
'-v', '/:/host', # ignored on Circle '-i',
docker_image, '/bin/bash']) '-v', '/:/host', # ignored on Circle
run_docker(['cp', os.path.abspath(project_dir) + '/.', container_name + ':/project']) docker_image, '/bin/bash'])
script_returncode = run_docker(['start', '-i', '-a', container_name], stdin_str=bash_script) run_docker(['cp', os.path.abspath(project_dir) + '/.', container_name + ':/project'])
run_docker(['cp', container_name + ':/output/.', os.path.abspath(output_dir)]) run_docker(['start', '-i', '-a', container_name], stdin_str=bash_script)
run_docker(['rm', '-v', container_name]) run_docker(['cp', container_name + ':/output/.', os.path.abspath(output_dir)])
except subprocess.CalledProcessError:
if script_returncode != 0:
exit(1) exit(1)
finally:
# Still gets executed, even when 'exit(1)' gets called
run_docker(['rm', '-v', container_name])