From 3b0d84af118d8bab82221cc11e1b16c715cce2f5 Mon Sep 17 00:00:00 2001 From: Luca Visentin Date: Fri, 16 Feb 2024 11:57:18 +0100 Subject: [PATCH] fix: fix bad parsing of root dir path --- src/commands/package.rs | 5 ++++- src/execution.rs | 18 +++++++++++++----- src/options.rs | 10 ++-------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/commands/package.rs b/src/commands/package.rs index 77d7b29..a2e7960 100644 --- a/src/commands/package.rs +++ b/src/commands/package.rs @@ -82,7 +82,10 @@ pub fn package_pipe(config: KerblamTomlOptions, pipe: Pipe, package_name: &str) // Write the container_file let workdir = config.execution.workdir.clone(); - let workdir = workdir.to_string_lossy(); + let workdir = match workdir { + Some(p) => format!("{}", p.to_string_lossy()), + None => "/".into(), + }; let content = match executor.strategy() { ExecutionStrategy::Make => format!( "FROM {base_container}\nCOPY . .\nENTRYPOINT [\"bash\", \"-c\", \"{workdir}/kerblam data fetch && make -C {workdir} -f {workdir}/executor\"]" diff --git a/src/execution.rs b/src/execution.rs index 04bdef5..517e277 100644 --- a/src/execution.rs +++ b/src/execution.rs @@ -6,7 +6,6 @@ use std::path::{Path, PathBuf}; use std::process::{Child, Command, ExitStatus, Stdio}; use crate::options::KerblamTomlOptions; -use crate::utils::normalize_path; use anyhow::{anyhow, bail, Context, Result}; use crossbeam_channel::{bounded, Receiver}; @@ -79,20 +78,25 @@ fn generate_bind_mount_strings(config: &KerblamTomlOptions) -> Vec { config.intermediate_data_dir(), ]; - let host_workdir = config.execution.workdir.clone(); + let host_workdir = match config.execution.workdir.clone() { + Some(p) => format!("{}", p.to_string_lossy()), + None => "/".into(), + }; + + log::debug!("Host workdir set to {host_workdir:?}"); for dir in dirs { // the folder here, in the local file system let local = dir.to_string_lossy(); // the folder in the host container let host = dir.strip_prefix(&root).unwrap().to_string_lossy(); - let host = host_workdir.join(format!("./{}", host)); - let host = normalize_path(&host); - let host = host.to_string_lossy(); + let host = format!("{host_workdir}/{host}"); result.push(format!("{}:{}", local, host)) } + log::debug!("Generated bind mount strings: {:?}", result); + result } @@ -128,6 +132,10 @@ impl Executor { // Add the correct entrypoint override let workdir = config.execution.workdir.clone(); + let workdir = match workdir { + Some(p) => p, + None => PathBuf::from("/"), + }; let workdir = workdir.to_string_lossy(); let execution_command: Vec = match self.strategy { ExecutionStrategy::Make => stringify!(vec![ diff --git a/src/options.rs b/src/options.rs index 6b55a6f..c07b6c6 100644 --- a/src/options.rs +++ b/src/options.rs @@ -61,8 +61,7 @@ pub struct KerblamTomlOptions { pub struct ExecutionOptions { #[serde(default)] pub backend: ContainerBackend, - #[serde(default = "_default_container_workdir")] - pub workdir: PathBuf, + pub workdir: Option, } #[derive(Deserialize, Debug, Clone)] @@ -87,11 +86,6 @@ impl From for String { } } -// This exists only to circumvent Serde's weird #[default] behaviour -fn _default_container_workdir() -> PathBuf { - PathBuf::from("/") -} - pub fn parse_kerblam_toml(toml_file: impl AsRef) -> Result { let toml_file = toml_file.as_ref(); log::debug!("Reading {:?} for TOML options...", toml_file); @@ -462,7 +456,7 @@ impl KerblamTomlOptions { .code .clone() .and_then(|x| x.env_dir) - .unwrap_or_else(|| current_dir().unwrap().join("src/containers")); + .unwrap_or_else(|| current_dir().unwrap().join("src/dockerfiles")); find_files(env, None) }