Skip to content

Commit

Permalink
build: change /workspace to /input and /ouput dirs (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleasims authored Nov 11, 2024
1 parent 8363c60 commit bafb5f8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 34 deletions.
6 changes: 3 additions & 3 deletions src/builders/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct BuildOptions {
pub nvidia_drivers: bool,
pub kernel_modules: Vec<String>,
pub mounts: Vec<String>,
pub no_gevulot_rt_config: bool,
pub no_gevulot_runtime: bool,
pub no_default_mounts: bool,
pub init: Option<String>,
pub init_args: Option<String>,
Expand Down Expand Up @@ -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!(
Expand Down Expand Up @@ -166,7 +166,7 @@ impl TryFrom<&clap::ArgMatches> for BuildOptions {
.unwrap_or_default()
.cloned()
.collect::<Vec<_>>(),
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::<String>("init").cloned(),
init_args: matches.get_one::<String>("init_args").cloned(),
Expand Down
60 changes: 33 additions & 27 deletions src/builders/skopeo_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"))?;
Expand Down Expand Up @@ -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(())
}
Expand Down Expand Up @@ -576,7 +580,7 @@ impl SkopeoSyslinuxBuilder {
container_rt_config: &MiaRuntimeConfig,
kernel_modules: &Vec<String>,
mounts: &Vec<String>,
gevulot_rt_config: bool,
gevulot_runtime: bool,
default_mounts: bool,
) -> Result<()> {
let mut mounts = mounts
Expand All @@ -600,33 +604,35 @@ impl SkopeoSyslinuxBuilder {
})
.collect::<Vec<_>>();

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(),
Expand Down
9 changes: 5 additions & 4 deletions src/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down

0 comments on commit bafb5f8

Please sign in to comment.