From 1980e870ba81bc27ad0f7d1073f41cb188b6bff6 Mon Sep 17 00:00:00 2001 From: Alex Zenla Date: Mon, 22 Jan 2024 02:26:43 -0800 Subject: [PATCH] hypha: init will now print the command from the image config --- hypha/src/container/init.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/hypha/src/container/init.rs b/hypha/src/container/init.rs index bd0553c..ee1307b 100644 --- a/hypha/src/container/init.rs +++ b/hypha/src/container/init.rs @@ -1,4 +1,5 @@ use crate::error::Result; +use oci_spec::image::ImageConfiguration; use std::fs; use std::path::Path; use sys_mount::{FilesystemType, Mount, MountFlags}; @@ -9,6 +10,8 @@ const CONFIG_BLOCK_DEVICE_PATH: &str = "/dev/xvdb"; const IMAGE_MOUNT_PATH: &str = "/image"; const CONFIG_MOUNT_PATH: &str = "/config"; +const IMAGE_CONFIG_JSON_PATH: &str = "/config/image/config.json"; + pub struct ContainerInit {} impl Default for ContainerInit { @@ -24,6 +27,12 @@ impl ContainerInit { pub fn init(&mut self) -> Result<()> { self.prepare_mounts()?; + let config = self.parse_image_config()?; + if let Some(cfg) = config.config() { + if let Some(cmd) = cfg.cmd() { + println!("image command: {:?}", cmd); + } + } Ok(()) } @@ -35,6 +44,12 @@ impl ContainerInit { Ok(()) } + fn parse_image_config(&mut self) -> Result { + let image_config_path = Path::new(IMAGE_CONFIG_JSON_PATH); + let config = ImageConfiguration::from_file(image_config_path)?; + Ok(config) + } + fn mount_squashfs(&mut self, from: &Path, to: &Path) -> Result<()> { if !to.is_dir() { fs::create_dir(to)?;