mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-07 13:41:21 +00:00
#298 Always clean-up after building container
This commit is contained in:
parent
9d91b96780
commit
1a76bfd2a3
@ -1,5 +1,4 @@
|
|||||||
import os
|
import os
|
||||||
from contextlib import contextmanager
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import shutil
|
import shutil
|
||||||
from tempfile import mkdtemp
|
from tempfile import mkdtemp
|
||||||
@ -15,12 +14,14 @@ enabled = os.environ.get('FUNCTIONAL')
|
|||||||
|
|
||||||
def build_container(tag, dockerfile):
|
def build_container(tag, dockerfile):
|
||||||
tmpdir = mkdtemp()
|
tmpdir = mkdtemp()
|
||||||
with Path(tmpdir).joinpath('Dockerfile').open('w') as file:
|
try:
|
||||||
file.write(dockerfile)
|
with Path(tmpdir).joinpath('Dockerfile').open('w') as file:
|
||||||
if subprocess.call(['docker', 'build', '--tag={}'.format(tag), tmpdir],
|
file.write(dockerfile)
|
||||||
cwd=root) != 0:
|
if subprocess.call(['docker', 'build', '--tag={}'.format(tag), tmpdir],
|
||||||
raise Exception("Can't build a container")
|
cwd=root) != 0:
|
||||||
shutil.rmtree(tmpdir)
|
raise Exception("Can't build a container")
|
||||||
|
finally:
|
||||||
|
shutil.rmtree(tmpdir)
|
||||||
|
|
||||||
|
|
||||||
def spawn(request, tag, dockerfile, cmd):
|
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 '
|
proc = pexpect.spawnu('docker run --volume {}:/src --tty=true '
|
||||||
'--interactive=true {} {}'.format(root, tag, cmd))
|
'--interactive=true {} {}'.format(root, tag, cmd))
|
||||||
proc.sendline('pip install /src')
|
proc.sendline('pip install /src')
|
||||||
|
proc.sendline('cd /')
|
||||||
|
|
||||||
proc.logfile = sys.stdout
|
proc.logfile = sys.stdout
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user