Skip to content

Commit

Permalink
feat: added support to run simulations with Docker images in Docker i…
Browse files Browse the repository at this point in the history
…mages
  • Loading branch information
jonrkarr committed Mar 30, 2022
1 parent c99d27c commit 2171183
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion biosimulators_utils/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.1.170'
__version__ = '0.1.171'
22 changes: 20 additions & 2 deletions biosimulators_utils/simulator/exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,21 @@ def exec_sedml_docs_in_archive_with_containerized_simulator(
# setup Docker run arguments
args = ['docker', 'run']

args.extend(['--mount', 'type=bind,source={},target={},readonly'.format(in_dir, image_in_dir)])
args.extend(['--mount', 'type=bind,source={},target={}'.format(os.path.abspath(out_dir), image_out_dir)])
temp_dir_host_path = os.getenv('TEMP_DIR_HOST_PATH', None)

if temp_dir_host_path:
temp_out_dir = tempfile.mkdtemp()

mount_in_dir = os.path.join(temp_dir_host_path, os.path.basename(in_dir))
mount_out_dir = os.path.join(temp_dir_host_path, os.path.basename(temp_out_dir))
else:
temp_out_dir = None

mount_in_dir = in_dir
mount_out_dir = os.path.abspath(out_dir)

args.extend(['--mount', 'type=bind,source={},target={},readonly'.format(mount_in_dir, image_in_dir)])
args.extend(['--mount', 'type=bind,source={},target={}'.format(mount_out_dir, image_out_dir)])

if environment:
for key, val in environment.items():
Expand Down Expand Up @@ -152,6 +165,9 @@ def exec_sedml_docs_in_archive_with_containerized_simulator(
try:
subprocess.check_call(args)

if temp_out_dir:
shutil.move(temp_out_dir, out_dir)

except FileNotFoundError:
raise RuntimeError("Docker could not be found")

Expand All @@ -165,6 +181,8 @@ def exec_sedml_docs_in_archive_with_containerized_simulator(

finally:
shutil.rmtree(in_dir)
if temp_out_dir and os.path.isdir(temp_out_dir):
shutil.rmtree(temp_out_dir)


def build_cli_args(archive_filename, out_dir):
Expand Down

0 comments on commit 2171183

Please sign in to comment.