Commit 23222d4a authored by Samuel GAIST's avatar Samuel GAIST Committed by Samuel GAIST

[execution][docker] Add support for custom mount points

Support giving a custom mount point to use for volume setup.

This will replace the cache path when creating the volumes.
parent 83d806eb
......@@ -279,7 +279,9 @@ class DockerExecutor(RemoteExecutor):
)
return retval
def __setup_io_volumes(self, algorithm_container, configuration):
def __setup_io_volumes(
self, algorithm_container, docker_cache_mount_point, configuration
):
"""Setup all the volumes for input and output files.
Parameters:
......@@ -293,25 +295,35 @@ class DockerExecutor(RemoteExecutor):
file_path = item["path"]
source_path = os.path.join(self.cache, file_path)
if os.path.isfile(source_path):
algorithm_container.add_volume(
source_path, os.path.join(self.CONTAINER_CACHE_PATH, file_path)
)
if docker_cache_mount_point is None:
if os.path.isfile(source_path):
algorithm_container.add_volume(
source_path, os.path.join(self.CONTAINER_CACHE_PATH, file_path)
)
else:
all_files = getAllFilenames(source_path)
for file_list in all_files:
for file_ in file_list:
target_path = file_[len(self.cache) + 1 :]
cache_path = os.path.join(
self.CONTAINER_CACHE_PATH, target_path
)
algorithm_container.add_volume(file_, cache_path)
else:
all_files = getAllFilenames(source_path)
for file_list in all_files:
for file_ in file_list:
target_path = file_[len(self.cache) + 1 :]
cache_path = os.path.join(
self.CONTAINER_CACHE_PATH, target_path
)
algorithm_container.add_volume(file_, cache_path)
input_folder = file_path[: file_path.rfind("/")]
source_folder = os.path.join(docker_cache_mount_point, input_folder)
target_folder = os.path.join(self.CONTAINER_CACHE_PATH, input_folder)
algorithm_container.add_volume(source_folder, target_folder)
def __add_writable_volume(file_path):
output_folder = file_path[: file_path.rfind("/")]
source_folder = os.path.join(self.cache, output_folder)
if not os.path.exists(source_folder):
os.makedirs(source_folder)
if docker_cache_mount_point is not None:
source_folder = os.path.join(docker_cache_mount_point, output_folder)
algorithm_container.add_volume(
source_folder,
os.path.join(self.CONTAINER_CACHE_PATH, output_folder),
......@@ -405,6 +417,8 @@ class DockerExecutor(RemoteExecutor):
port = utils.find_free_port_in_range(int(min_port), int(max_port))
address += ":{}".format(port)
volume_cache_mount_point = self.data.pop("cache_mount_point", None)
self.message_handler = MessageHandler(address, kill_callback=_kill)
# ----- (If necessary) Instantiate the docker container that provide the databases
......@@ -463,7 +477,9 @@ class DockerExecutor(RemoteExecutor):
loop_algorithm_container.add_volume(
configuration_path, self.CONTAINER_PREFIX_PATH
)
self.__setup_io_volumes(loop_algorithm_container, self.data["loop"])
self.__setup_io_volumes(
loop_algorithm_container, volume_cache_mount_point, self.data["loop"]
)
# Start the container
self.host.start(
......@@ -505,7 +521,9 @@ class DockerExecutor(RemoteExecutor):
# Volumes
algorithm_container.add_volume(configuration_path, self.CONTAINER_PREFIX_PATH)
self.__setup_io_volumes(algorithm_container, self.data)
self.__setup_io_volumes(
algorithm_container, volume_cache_mount_point, self.data
)
# Start the container
self.host.start(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment