1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-01-31 10:11:14 +00:00

#298 Always clean-up after building container

This commit is contained in:
nvbn 2015-07-30 18:17:29 +03:00
parent 9d91b96780
commit 1a76bfd2a3

View File

@ -1,5 +1,4 @@
import os
from contextlib import contextmanager
import subprocess
import shutil
from tempfile import mkdtemp
@ -15,12 +14,14 @@ enabled = os.environ.get('FUNCTIONAL')
def build_container(tag, dockerfile):
tmpdir = mkdtemp()
with Path(tmpdir).joinpath('Dockerfile').open('w') as file:
file.write(dockerfile)
if subprocess.call(['docker', 'build', '--tag={}'.format(tag), tmpdir],
cwd=root) != 0:
raise Exception("Can't build a container")
shutil.rmtree(tmpdir)
try:
with Path(tmpdir).joinpath('Dockerfile').open('w') as file:
file.write(dockerfile)
if subprocess.call(['docker', 'build', '--tag={}'.format(tag), tmpdir],
cwd=root) != 0:
raise Exception("Can't build a container")
finally:
shutil.rmtree(tmpdir)
def spawn(request, tag, dockerfile, cmd):
@ -32,6 +33,7 @@ def spawn(request, tag, dockerfile, cmd):
proc = pexpect.spawnu('docker run --volume {}:/src --tty=true '
'--interactive=true {} {}'.format(root, tag, cmd))
proc.sendline('pip install /src')
proc.sendline('cd /')
proc.logfile = sys.stdout