From ba76d8749a9524ed356611c09f874da60f3b954a Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Fri, 21 Jun 2024 18:07:52 +0200 Subject: [PATCH] fix: improve support of relative paths in subflows and apps --- backend/windmill-worker/src/bun_executor.rs | 10 ++++++++-- backend/windmill-worker/src/common.rs | 16 ++++++++++++++++ backend/windmill-worker/src/deno_executor.rs | 3 ++- backend/windmill-worker/src/python_executor.rs | 6 +++--- backend/windmill-worker/src/worker_lockfiles.rs | 7 +++++-- 5 files changed, 34 insertions(+), 8 deletions(-) diff --git a/backend/windmill-worker/src/bun_executor.rs b/backend/windmill-worker/src/bun_executor.rs index cdf9a02882..44085ecfbb 100644 --- a/backend/windmill-worker/src/bun_executor.rs +++ b/backend/windmill-worker/src/bun_executor.rs @@ -85,7 +85,10 @@ pub async fn gen_lockfile( .replace("W_ID", w_id) .replace("BASE_INTERNAL_URL", base_internal_url) .replace("TOKEN", token) - .replace("CURRENT_PATH", script_path) + .replace( + "CURRENT_PATH", + &crate::common::use_flow_root_path(script_path) + ) .replace("RAW_GET_ENDPOINT", "raw") ), ) @@ -305,7 +308,10 @@ pub async fn build_loader( .replace("W_ID", w_id) .replace("BASE_INTERNAL_URL", base_internal_url) .replace("TOKEN", token) - .replace("CURRENT_PATH", current_path) + .replace( + "CURRENT_PATH", + &crate::common::use_flow_root_path(current_path), + ) .replace("RAW_GET_ENDPOINT", "raw_unpinned"); if nodejs_mode { write_file( diff --git a/backend/windmill-worker/src/common.rs b/backend/windmill-worker/src/common.rs index 675aca89be..95f4759400 100644 --- a/backend/windmill-worker/src/common.rs +++ b/backend/windmill-worker/src/common.rs @@ -1599,3 +1599,19 @@ pub async fn clean_cache() -> error::Result<()> { tracing::info!("Finished cleaning cache"); Ok(()) } + +lazy_static::lazy_static! { + static ref RE_FLOW_ROOT: Regex = Regex::new(r"(?i)(.*?)(?:/branchone-\d+/|/branchall-\d+/|/loop-\d+/)").unwrap(); + +} + +pub fn use_flow_root_path(flow_path: &str) -> String { + if let Some(captures) = RE_FLOW_ROOT.captures(flow_path) { + return captures + .get(1) + .map(|m| format!("{}/flow", m.as_str())) + .unwrap_or_else(|| flow_path.to_string()); + } else { + return flow_path.to_string(); + } +} diff --git a/backend/windmill-worker/src/deno_executor.rs b/backend/windmill-worker/src/deno_executor.rs index f082c113ea..ac1b4a6edd 100644 --- a/backend/windmill-worker/src/deno_executor.rs +++ b/backend/windmill-worker/src/deno_executor.rs @@ -355,7 +355,8 @@ async fn build_import_map( base_internal_url: &str, job_dir: &str, ) -> error::Result<()> { - let script_path_split = script_path.split("/"); + let rooted_path = crate::common::use_flow_root_path(script_path); + let script_path_split = rooted_path.split("/"); let script_path_parts_len = script_path_split.clone().count(); let mut relative_mounts = "".to_string(); for c in 0..script_path_parts_len { diff --git a/backend/windmill-worker/src/python_executor.rs b/backend/windmill-worker/src/python_executor.rs index 5efa15d780..84bbd8c31c 100644 --- a/backend/windmill-worker/src/python_executor.rs +++ b/backend/windmill-worker/src/python_executor.rs @@ -247,13 +247,13 @@ pub async fn handle_python_job( base_internal_url: &str, envs: HashMap, ) -> windmill_common::error::Result> { - let script_path = job.script_path(); + let script_path = crate::common::use_flow_root_path(job.script_path()); let additional_python_paths = handle_python_deps( job_dir, requirements_o, inner_content, &job.workspace_id, - script_path, + &script_path, &job.id, db, worker_name, @@ -281,7 +281,7 @@ pub async fn handle_python_job( transforms, spread, main_name, - ) = prepare_wrapper(job_dir, inner_content, script_path, job.args.as_ref()).await?; + ) = prepare_wrapper(job_dir, inner_content, &script_path, job.args.as_ref()).await?; create_args_and_out_file(&client, job, job_dir, db).await?; diff --git a/backend/windmill-worker/src/worker_lockfiles.rs b/backend/windmill-worker/src/worker_lockfiles.rs index c70ee9b487..c789174bc0 100644 --- a/backend/windmill-worker/src/worker_lockfiles.rs +++ b/backend/windmill-worker/src/worker_lockfiles.rs @@ -797,7 +797,10 @@ async fn lock_modules<'c>( worker_dir, base_internal_url, token, - &path.clone().unwrap_or_else(|| job_path.to_string()), + &format!( + "{}/flow", + &path.clone().unwrap_or_else(|| job_path.to_string()) + ), false, ) .await; @@ -925,7 +928,7 @@ async fn lock_modules_app( worker_dir, base_internal_url, token, - job.script_path(), + &format!("{}/app", job.script_path()), false, ) .await;