diff --git a/src/builders/mod.rs b/src/builders/mod.rs index 1fc7b17..1f7837b 100644 --- a/src/builders/mod.rs +++ b/src/builders/mod.rs @@ -19,7 +19,7 @@ pub struct BuildOptions { pub nvidia_drivers: bool, pub kernel_modules: Vec, pub mounts: Vec, - pub no_gevulot_rt_config: bool, + pub no_gevulot_runtime: bool, pub no_default_mounts: bool, pub init: Option, pub init_args: Option, @@ -101,7 +101,7 @@ impl std::fmt::Display for BuildOptions { writeln!( f, "| Gevulot runtime | {:<42} |", - !self.no_gevulot_rt_config + !self.no_gevulot_runtime )?; writeln!(f, "| Default mounts | {:<42} |", !self.no_default_mounts)?; writeln!( @@ -166,7 +166,7 @@ impl TryFrom<&clap::ArgMatches> for BuildOptions { .unwrap_or_default() .cloned() .collect::>(), - no_gevulot_rt_config: matches.get_flag("no_gevulot_rt_config"), + no_gevulot_runtime: matches.get_flag("no_gevulot_runtime"), no_default_mounts: matches.get_flag("no_default_mounts"), init: matches.get_one::("init").cloned(), init_args: matches.get_one::("init_args").cloned(), diff --git a/src/builders/skopeo_builder.rs b/src/builders/skopeo_builder.rs index a0bf095..9c95214 100644 --- a/src/builders/skopeo_builder.rs +++ b/src/builders/skopeo_builder.rs @@ -93,8 +93,8 @@ impl ImageBuilder for SkopeoSyslinuxBuilder { print(&format!("✅\n"))?; } - print("Creating workspace directory...")?; - Self::create_workspace()?; + print("Creating input/output context directories...")?; + Self::create_mount_dirs()?; print("✅\n")?; if let Some(kernel_path) = &options.kernel_file { @@ -125,7 +125,7 @@ impl ImageBuilder for SkopeoSyslinuxBuilder { &container_rt_config, &kernel_modules, &options.mounts, - !options.no_gevulot_rt_config, + !options.no_gevulot_runtime, !options.no_default_mounts, )?; print(&format!("✅\n"))?; @@ -464,11 +464,15 @@ impl SkopeoSyslinuxBuilder { .context("Failed to install rootfs from built container") } - /// Create `/workspace` directory in the VM, which will be used as output mountpoint. - fn create_workspace() -> Result<()> { - let ws_path = env::temp_dir().join("mnt").join("workspace"); - if !ws_path.exists() { - fs::create_dir_all(&ws_path).context("Failed to create workspace directory")?; + /// Create `/mnt/input` and `/mnt/output` directories in the VM, which will be used as input and + /// output context mountpoints. + fn create_mount_dirs() -> Result<()> { + let mnt = env::temp_dir().join("mnt").join("mnt"); + for path in [mnt.join("input"), mnt.join("output")] { + if !path.exists() { + fs::create_dir_all(&path) + .context(format!("Failed to create {} directory", path.display()))?; + } } Ok(()) } @@ -576,7 +580,7 @@ impl SkopeoSyslinuxBuilder { container_rt_config: &MiaRuntimeConfig, kernel_modules: &Vec, mounts: &Vec, - gevulot_rt_config: bool, + gevulot_runtime: bool, default_mounts: bool, ) -> Result<()> { let mut mounts = mounts @@ -600,33 +604,35 @@ impl SkopeoSyslinuxBuilder { }) .collect::>(); - let follow_config = if gevulot_rt_config { + let follow_config = if gevulot_runtime { + let gevulot_mnt_dir = env::temp_dir().join("mnt").join("mnt").join("gevulot"); + for dirname in ["rt-config", "input", "output"] { + let dirpath = gevulot_mnt_dir.join(dirname); + Self::run_command(&["mkdir", "-p", dirpath.to_str().unwrap()], true) + .context(format!("Failed to create {} directory", dirpath.display()))?; + } + + // NOTE: Worker node will mount input and output contexts to these tags. + mounts.push(mia_rt_config::Mount::virtio9p( + "gevulot-input".to_string(), + "/mnt/gevulot/input".to_string(), + )); + mounts.push(mia_rt_config::Mount::virtio9p( + "gevulot-output".to_string(), + "/mnt/gevulot/output".to_string(), + )); + mounts.push(mia_rt_config::Mount::virtio9p( "gevulot-rt-config".to_string(), - "/mnt/gevulot-rt-config".to_string(), + "/mnt/gevulot/rt-config".to_string(), )); // NOTE: Worker node will mount runtime config file to tag `gevulot-rt-config`. // This is a convention between VM and node we have now. - Some("/mnt/gevulot-rt-config/config.yaml".to_string()) + Some("/mnt/gevulot/rt-config/config.yaml".to_string()) } else { None }; - Self::run_command( - &[ - "mkdir", - "-p", - env::temp_dir() - .join("mnt") - .join("mnt") - .join("gevulot-rt-config") - .to_str() - .unwrap(), - ], - true, - ) - .context("Failed to create gevulot-rt-config directory")?; - let rt_config = MiaRuntimeConfig { version: mia_rt_config::VERSION, command: container_rt_config.command.clone(), diff --git a/src/commands/build.rs b/src/commands/build.rs index 3cabde6..7ee4c15 100644 --- a/src/commands/build.rs +++ b/src/commands/build.rs @@ -116,11 +116,12 @@ pub fn get_command() -> clap::Command { .required(false), ) .arg( - Arg::new("no_gevulot_rt_config") - .long("no-gevulot-rt-config") - .help("[MIA] Don't mount gevulot-rt-config. Only for debug purposes.") - .help("[MIA] Don't mount gevulot-rt-config. Only for debug purposes.\n\ + Arg::new("no_gevulot_runtime") + .long("no-gevulot-runtime") + .help("[MIA] Don't install Gevulot runtime. Only for debug purposes.") + .help("[MIA] Don't install Gevulot runtime. Only for debug purposes.\n\ No following config will be provided to the VM. Only built-in one will be used.\n\ + No input/output context directories will be mounted.\n\ Note: Gevulot worker will provide runtime config through gevulot-rt-config.\n\ This means that images with this flag enabled cannot be executed on the network.\n\ This option can't be used together with --init or --init-args.")