build.run: fix execute_local_docker()
not exiting docker container on SIGINT
This commit is contained in:
parent
cd083aac14
commit
514ff0bcbc
|
@ -9,6 +9,7 @@ import warnings
|
||||||
import zipfile
|
import zipfile
|
||||||
import hashlib
|
import hashlib
|
||||||
import pathlib
|
import pathlib
|
||||||
|
import random
|
||||||
|
|
||||||
|
|
||||||
__all__ = ["BuildPlan", "BuildProducts", "LocalBuildProducts", "RemoteSSHBuildProducts"]
|
__all__ = ["BuildPlan", "BuildProducts", "LocalBuildProducts", "RemoteSSHBuildProducts"]
|
||||||
|
@ -135,14 +136,22 @@ class BuildPlan:
|
||||||
Returns :class:`LocalBuildProducts`.
|
Returns :class:`LocalBuildProducts`.
|
||||||
"""
|
"""
|
||||||
build_dir = self.extract(root)
|
build_dir = self.extract(root)
|
||||||
subprocess.check_call([
|
container_name = f"amaranth_build_{random.randbytes(8).hex()}"
|
||||||
"docker", "run", *docker_args,
|
try:
|
||||||
"--rm", # remove the container after running
|
subprocess.check_call([
|
||||||
"--mount", f"type=bind,source={build_dir},target=/build",
|
"docker", "run", *docker_args,
|
||||||
"--workdir", "/build",
|
"--rm", # remove the container after running
|
||||||
image,
|
"--init", # run an init process as PID 1. Helps exit faster
|
||||||
"sh", f"{self.script}.sh",
|
"--name", container_name,
|
||||||
])
|
"--mount", f"type=bind,source={build_dir},target=/build",
|
||||||
|
"--workdir", "/build",
|
||||||
|
image,
|
||||||
|
"sh", f"{self.script}.sh",
|
||||||
|
])
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
subprocess.check_call([
|
||||||
|
"docker", "stop", container_name
|
||||||
|
], stdout=subprocess.DEVNULL)
|
||||||
return LocalBuildProducts(build_dir)
|
return LocalBuildProducts(build_dir)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue