mirror of
https://github.com/edera-dev/krata.git
synced 2025-08-04 13:41:31 +00:00
hypha: implement the ability to override the command line to execute
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
use crate::error::Result;
|
||||
use crate::image::ImageInfo;
|
||||
use crate::shared::LaunchInfo;
|
||||
use backhand::{FilesystemWriter, NodeHeader};
|
||||
use std::fs;
|
||||
use std::fs::File;
|
||||
@ -32,12 +33,13 @@ impl ConfigBlock<'_> {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn build(&self) -> Result<()> {
|
||||
pub fn build(&self, launch_config: &LaunchInfo) -> Result<()> {
|
||||
let config_bundle_content = match self.config_bundle {
|
||||
None => None,
|
||||
Some(path) => Some(fs::read(path)?),
|
||||
};
|
||||
let manifest = self.image_info.config.to_string()?;
|
||||
let launch = serde_json::to_string(launch_config)?;
|
||||
let mut writer = FilesystemWriter::default();
|
||||
writer.push_dir(
|
||||
"/image",
|
||||
@ -58,6 +60,16 @@ impl ConfigBlock<'_> {
|
||||
mtime: 0,
|
||||
},
|
||||
)?;
|
||||
writer.push_file(
|
||||
launch.as_bytes(),
|
||||
"/launch.json",
|
||||
NodeHeader {
|
||||
permissions: 384,
|
||||
uid: 0,
|
||||
gid: 0,
|
||||
mtime: 0,
|
||||
},
|
||||
)?;
|
||||
if let Some(config_bundle_content) = config_bundle_content.as_ref() {
|
||||
writer.push_file(
|
||||
config_bundle_content.as_slice(),
|
||||
|
@ -6,6 +6,7 @@ use crate::error::{HyphaError, Result};
|
||||
use crate::image::cache::ImageCache;
|
||||
use crate::image::name::ImageName;
|
||||
use crate::image::{ImageCompiler, ImageInfo};
|
||||
use crate::shared::LaunchInfo;
|
||||
use loopdev::LoopControl;
|
||||
use std::io::{Read, Write};
|
||||
use std::path::PathBuf;
|
||||
@ -59,6 +60,7 @@ impl Controller {
|
||||
compiler.compile(&image)
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn launch(
|
||||
&mut self,
|
||||
kernel_path: &str,
|
||||
@ -67,12 +69,15 @@ impl Controller {
|
||||
image: &str,
|
||||
vcpus: u32,
|
||||
mem: u64,
|
||||
run: Option<Vec<String>>,
|
||||
) -> Result<u32> {
|
||||
let uuid = Uuid::new_v4();
|
||||
let name = format!("hypha-{uuid}");
|
||||
let image_info = self.compile(image)?;
|
||||
let launch_config = LaunchInfo { run };
|
||||
|
||||
let cfgblk = ConfigBlock::new(&uuid, &image_info, config_bundle_path)?;
|
||||
cfgblk.build()?;
|
||||
cfgblk.build(&launch_config)?;
|
||||
|
||||
let image_squashfs_path = image_info
|
||||
.image_squashfs
|
||||
|
Reference in New Issue
Block a user