Ditching run_docker for subprocess.run
This commit is contained in:
+11
-25
@@ -147,38 +147,24 @@ def build(project_dir, output_dir, test_command, test_requires, test_extras, bef
|
|||||||
gid=os.getgid(),
|
gid=os.getgid(),
|
||||||
)
|
)
|
||||||
|
|
||||||
def run_docker(command, stdin_str=None):
|
|
||||||
print('docker command: docker {}'.format(' '.join(map(shlex_quote, command))))
|
|
||||||
if stdin_str is None:
|
|
||||||
subprocess.check_call(['docker'] + command)
|
|
||||||
else:
|
|
||||||
args = ['docker'] + command
|
|
||||||
process = subprocess.Popen(args, stdin=subprocess.PIPE, universal_newlines=True)
|
|
||||||
try:
|
|
||||||
process.communicate(stdin_str)
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
process.kill()
|
|
||||||
process.wait()
|
|
||||||
if process.returncode != 0:
|
|
||||||
raise subprocess.CalledProcessError(process.returncode, args)
|
|
||||||
|
|
||||||
container_name = 'cibuildwheel-{}'.format(uuid.uuid4())
|
container_name = 'cibuildwheel-{}'.format(uuid.uuid4())
|
||||||
try:
|
try:
|
||||||
run_docker(['create',
|
subprocess.run(['docker', 'create',
|
||||||
'--env', 'CIBUILDWHEEL',
|
'--env', 'CIBUILDWHEEL',
|
||||||
'--name', container_name,
|
'--name', container_name,
|
||||||
'-i',
|
'-i',
|
||||||
'-v', '/:/host', # ignored on Circle
|
'-v', '/:/host', # ignored on CircleCI
|
||||||
docker_image, '/bin/bash'])
|
docker_image, '/bin/bash'],
|
||||||
run_docker(['cp', os.path.abspath(project_dir) + '/.', container_name + ':/project'])
|
check=True)
|
||||||
run_docker(['start', '-i', '-a', container_name], stdin_str=bash_script)
|
subprocess.run(['docker', 'cp', os.path.abspath(project_dir) + '/.', container_name + ':/project'], check=True)
|
||||||
run_docker(['cp', container_name + ':/output/.', os.path.abspath(output_dir)])
|
subprocess.run(['docker', 'start', '-i', '-a', container_name], input=bash_script, universal_newlines=True, check=True)
|
||||||
|
subprocess.run(['docker', 'cp', container_name + ':/output/.', os.path.abspath(output_dir)], check=True)
|
||||||
except subprocess.CalledProcessError as error:
|
except subprocess.CalledProcessError as error:
|
||||||
troubleshoot(project_dir, error)
|
troubleshoot(project_dir, error)
|
||||||
exit(1)
|
exit(1)
|
||||||
finally:
|
finally:
|
||||||
# Still gets executed, even when 'exit(1)' gets called
|
# Still gets executed, even when 'exit(1)' gets called
|
||||||
run_docker(['rm', '--force', '-v', container_name])
|
subprocess.run(['docker', 'rm', '--force', '-v', container_name], check=True)
|
||||||
|
|
||||||
|
|
||||||
def troubleshoot(project_dir, error):
|
def troubleshoot(project_dir, error):
|
||||||
|
|||||||
Reference in New Issue
Block a user