def _prepare_task_env(conf: AiscalatorConfig): """ Assemble the list of volumes to mount specific to the task execution Parameters ---------- conf : AiscalatorConfig Configuration object for the step Returns ------- list list of commands to bind those volumes """ commands = [] if conf.root_dir(): commands += _mount_path(conf, "task.modules_src_path", "/home/jovyan/work/modules/") commands += _mount_path(conf, "task.input_data_path", "/home/jovyan/work/data/input/", readonly=True) commands += _mount_path(conf, "task.output_data_path", "/home/jovyan/work/data/output/", make_dirs=True) return commands
def _mount_path(conf: AiscalatorConfig, field, target_path, readonly=False, make_dirs=False): """ Returu commands to mount path from list field into the docker image when running. Parameters ---------- conf : AiscalatorConfig Configuration object for the step field : str the field in the configuration step that contains the path target_path : str where to mount them inside the container readonly : bool flag to mount the path as read-only make_dirs : bool flag to create the folder on the host before mounting if it doesn't exists. Returns ------- list commands to mount all the paths from the field """ commands = [] if conf.has_step_field(field): for value in conf.step_field(field): # TODO handle URL for i in value: if make_dirs: makedirs(os.path.realpath(conf.root_dir() + value[i]), exist_ok=True) if os.path.exists(conf.root_dir() + value[i]): commands += [ "--mount", "type=bind,source=" + os.path.realpath(conf.root_dir() + value[i]) + ",target=" + os.path.join(target_path, i) + (",readonly" if readonly else "") ] return commands