diff --git a/recipe/src/module.rs b/recipe/src/module.rs index 04a9235..b50778d 100644 --- a/recipe/src/module.rs +++ b/recipe/src/module.rs @@ -89,7 +89,7 @@ impl<'a> Module<'a> { } #[must_use] - pub fn generate_akmods_info(&'a self, os_version: &str) -> AkmodsInfo { + pub fn generate_akmods_info(&'a self, os_version: &u64) -> AkmodsInfo { #[derive(Debug, Copy, Clone)] enum NvidiaAkmods { Nvidia(bool), diff --git a/recipe/src/module_ext.rs b/recipe/src/module_ext.rs index 58a3b90..a6e1885 100644 --- a/recipe/src/module_ext.rs +++ b/recipe/src/module_ext.rs @@ -45,7 +45,7 @@ impl ModuleExt<'_> { } #[must_use] - pub fn get_akmods_info_list(&self, os_version: &str) -> Vec { + pub fn get_akmods_info_list(&self, os_version: &u64) -> Vec { trace!("get_akmods_image_list({self:#?}, {os_version})"); let mut seen = HashSet::new(); diff --git a/recipe/src/recipe.rs b/recipe/src/recipe.rs index 30d60e4..7145169 100644 --- a/recipe/src/recipe.rs +++ b/recipe/src/recipe.rs @@ -44,7 +44,7 @@ pub struct Recipe<'a> { impl<'a> Recipe<'a> { #[must_use] - pub fn generate_tags(&self, os_version: &str) -> Vec { + pub fn generate_tags(&self, os_version: u64) -> Vec { trace!("Recipe::generate_tags()"); trace!("Generating image tags for {}", &self.name); diff --git a/src/commands/build.rs b/src/commands/build.rs index 08e05ab..28b20ac 100644 --- a/src/commands/build.rs +++ b/src/commands/build.rs @@ -211,7 +211,7 @@ impl BuildCommand { let recipe = Recipe::parse(&recipe_path)?; let os_version = Driver::get_os_version(&recipe)?; - let tags = recipe.generate_tags(&os_version); + let tags = recipe.generate_tags(os_version); let image_name = self.generate_full_image_name(&recipe)?; if self.push { diff --git a/src/drivers.rs b/src/drivers.rs index b48e891..b88986c 100644 --- a/src/drivers.rs +++ b/src/drivers.rs @@ -95,7 +95,7 @@ static INSPECT_DRIVER: Lazy> = Lazy::new(|| { static BUILD_ID: Lazy = Lazy::new(Uuid::new_v4); /// The cached os versions -static OS_VERSION: Lazy>> = Lazy::new(|| Mutex::new(HashMap::new())); +static OS_VERSION: Lazy>> = Lazy::new(|| Mutex::new(HashMap::new())); /// Trait for retrieving version of a driver. pub trait DriverVersion { @@ -309,7 +309,7 @@ impl Driver<'_> { /// # Errors /// Will error if the image doesn't have OS version info /// or we are unable to lock a mutex. - pub fn get_os_version(recipe: &Recipe) -> Result { + pub fn get_os_version(recipe: &Recipe) -> Result { trace!("Driver::get_os_version({recipe:#?})"); let image = format!("{}:{}", &recipe.base_image, &recipe.image_version); @@ -339,13 +339,13 @@ impl Driver<'_> { } Some(os_version) => { debug!("Found cached {os_version} for {image}"); - os_version.clone() + *os_version } }; if let Entry::Vacant(entry) = os_version_lock.entry(image.clone()) { trace!("Caching version {os_version} for {image}"); - entry.insert(os_version.clone()); + entry.insert(os_version); } drop(os_version_lock); Ok(os_version) diff --git a/src/image_metadata.rs b/src/image_metadata.rs index 4b1eb0e..36631ee 100644 --- a/src/image_metadata.rs +++ b/src/image_metadata.rs @@ -1,4 +1,5 @@ use blue_build_utils::constants::IMAGE_VERSION_LABEL; +use semver::Version; use serde::Deserialize; use serde_json::Value; use std::collections::HashMap; @@ -13,15 +14,14 @@ pub struct ImageMetadata { } impl ImageMetadata { - pub fn get_version(&self) -> Option { + #[must_use] + pub fn get_version(&self) -> Option { Some( self.labels .get(IMAGE_VERSION_LABEL)? .as_str() - .map(std::string::ToString::to_string)? - .split('.') - .take(1) - .collect(), + .and_then(|v| Version::parse(v).ok())? + .major, ) } } diff --git a/template/src/lib.rs b/template/src/lib.rs index 47ff805..9c3badf 100644 --- a/template/src/lib.rs +++ b/template/src/lib.rs @@ -23,8 +23,7 @@ pub struct ContainerFileTemplate<'a> { #[builder(setter(into))] build_id: Uuid, - #[builder(setter(into))] - os_version: Cow<'a, str>, + os_version: u64, #[builder(setter(into))] registry: Cow<'a, str>,