Skip to content

Commit

Permalink
fix: fix bad parsing of root dir path
Browse files Browse the repository at this point in the history
  • Loading branch information
MrHedmad committed Feb 16, 2024
1 parent 81ec1be commit 3b0d84a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
5 changes: 4 additions & 1 deletion src/commands/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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\"]"
Expand Down
18 changes: 13 additions & 5 deletions src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -79,20 +78,25 @@ fn generate_bind_mount_strings(config: &KerblamTomlOptions) -> Vec<String> {
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
}

Expand Down Expand Up @@ -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<String> = match self.strategy {
ExecutionStrategy::Make => stringify!(vec![
Expand Down
10 changes: 2 additions & 8 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf>,
}

#[derive(Deserialize, Debug, Clone)]
Expand All @@ -87,11 +86,6 @@ impl From<ContainerBackend> 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<Path>) -> Result<KerblamTomlOptions> {
let toml_file = toml_file.as_ref();
log::debug!("Reading {:?} for TOML options...", toml_file);
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 3b0d84a

Please sign in to comment.