mirror of
https://github.com/edera-dev/krata.git
synced 2025-08-02 12:50:54 +00:00
hypha: add support for passing environment variables
This commit is contained in:
parent
5e21d32295
commit
bb77e651e0
@ -30,6 +30,8 @@ enum Commands {
|
||||
mem: u64,
|
||||
#[arg(long)]
|
||||
config_bundle: Option<String>,
|
||||
#[arg[short, long]]
|
||||
env: Option<Vec<String>>,
|
||||
#[arg(allow_hyphen_values = true, trailing_var_arg = true)]
|
||||
run: Vec<String>,
|
||||
},
|
||||
@ -68,20 +70,22 @@ fn main() -> Result<()> {
|
||||
cpus,
|
||||
mem,
|
||||
config_bundle,
|
||||
env,
|
||||
run,
|
||||
} => {
|
||||
let kernel = map_kernel_path(&store_path, kernel);
|
||||
let initrd = map_initrd_path(&store_path, initrd);
|
||||
let domid = controller.launch(
|
||||
let (uuid, _domid) = controller.launch(
|
||||
&kernel,
|
||||
&initrd,
|
||||
config_bundle.as_deref(),
|
||||
&image,
|
||||
cpus,
|
||||
mem,
|
||||
env,
|
||||
if run.is_empty() { None } else { Some(run) },
|
||||
)?;
|
||||
println!("launched domain: {}", domid);
|
||||
println!("launched container: {}", uuid);
|
||||
}
|
||||
|
||||
Commands::Destroy { domain } => {
|
||||
|
@ -288,6 +288,9 @@ impl ContainerInit {
|
||||
Some(value) => value.clone(),
|
||||
};
|
||||
env.push("HYPHA_CONTAINER=1".to_string());
|
||||
if let Some(extra_env) = &launch.env {
|
||||
env.extend_from_slice(extra_env.as_slice());
|
||||
}
|
||||
let path_cstr = CString::new(path)?;
|
||||
let cmd_cstr = ContainerInit::strings_as_cstrings(cmd)?;
|
||||
let env_cstr = ContainerInit::strings_as_cstrings(env)?;
|
||||
|
@ -69,12 +69,13 @@ impl Controller {
|
||||
image: &str,
|
||||
vcpus: u32,
|
||||
mem: u64,
|
||||
env: Option<Vec<String>>,
|
||||
run: Option<Vec<String>>,
|
||||
) -> Result<u32> {
|
||||
) -> Result<(Uuid, u32)> {
|
||||
let uuid = Uuid::new_v4();
|
||||
let name = format!("hypha-{uuid}");
|
||||
let image_info = self.compile(image)?;
|
||||
let launch_config = LaunchInfo { run };
|
||||
let launch_config = LaunchInfo { env, run };
|
||||
|
||||
let cfgblk = ConfigBlock::new(&uuid, &image_info, config_bundle_path)?;
|
||||
cfgblk.build(&launch_config)?;
|
||||
@ -134,7 +135,7 @@ impl Controller {
|
||||
],
|
||||
};
|
||||
match self.client.create(&config) {
|
||||
Ok(domid) => Ok(domid),
|
||||
Ok(domid) => Ok((uuid, domid)),
|
||||
Err(error) => {
|
||||
let _ = self.autoloop.unloop(&image_squashfs_loop.path);
|
||||
let _ = self.autoloop.unloop(&cfgblk_squashfs_loop.path);
|
||||
|
@ -2,5 +2,6 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct LaunchInfo {
|
||||
pub env: Option<Vec<String>>,
|
||||
pub run: Option<Vec<String>>,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user