Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update akmods module to account for upstream changes #165

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions integration-tests/test-repo/recipes/akmods.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ modules:
# Tests installing rpms from a combo image stage
- type: akmods
base: surface
nvidia-version: 545
nvidia: true
# install:
# - nvidia
# - openrazer
Expand All @@ -15,7 +15,7 @@ modules:

# Tests pulling image for main nvidia
- type: akmods
nvidia-version: 545
nvidia: true

# Test pulling image for base asus
- type: akmods
Expand Down
46 changes: 37 additions & 9 deletions recipe/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{borrow::Cow, process};

use anyhow::{bail, Result};
use indexmap::IndexMap;
use log::{error, trace};
use log::{error, trace, warn};
use serde::{Deserialize, Serialize};
use serde_yaml::Value;
use typed_builder::TypedBuilder;
Expand Down Expand Up @@ -88,26 +88,50 @@ impl<'a> Module<'a> {
})
}

#[must_use]
pub fn generate_akmods_info(&'a self, os_version: &str) -> AkmodsInfo {
#[derive(Debug, Copy, Clone)]
enum NvidiaAkmods {
Nvidia(bool),
Version(u64),
}

trace!("generate_akmods_base({self:#?}, {os_version})");

let base = self
.config
.get("base")
.map(|b| b.as_str().unwrap_or_default());
let nvidia_version = self
.config
.get("nvidia-version")
.map(|v| v.as_u64().unwrap_or_default());
let nvidia = self.config.get("nvidia-version").map_or_else(
|| {
self.config
.get("nvidia")
.map_or_else(|| NvidiaAkmods::Nvidia(false), |v| NvidiaAkmods::Nvidia(v.as_bool().unwrap_or_default()))
},
|v| {
warn!(
"The `nvidia-version` property is deprecated as upstream images may no longer exist, replace it with `nvidia: true`"
);
NvidiaAkmods::Version(v.as_u64().unwrap_or_default())
},
);

AkmodsInfo::builder()
.images(match (base, nvidia_version) {
(Some(b), Some(nv)) if !b.is_empty() && nv > 0 => (
.images(match (base, nvidia) {
(Some(b), NvidiaAkmods::Nvidia(nv)) if !b.is_empty() && nv => (
format!("akmods:{b}-{os_version}"),
Some(format!("akmods-nvidia:{b}-{os_version}")),
),
(Some(b), NvidiaAkmods::Version(nv)) if !b.is_empty() && nv > 0 => (
format!("akmods:{b}-{os_version}"),
Some(format!("akmods-nvidia:{b}-{os_version}-{nv}")),
),
(Some(b), _) if !b.is_empty() => (format!("akmods:{b}-{os_version}"), None),
(_, Some(nv)) if nv > 0 => (
(_, NvidiaAkmods::Nvidia(nv)) if nv => (
format!("akmods:main-{os_version}"),
Some(format!("akmods-nvidia:main-{os_version}")),
),
(_, NvidiaAkmods::Version(nv)) if nv > 0 => (
format!("akmods:main-{os_version}"),
Some(format!("akmods-nvidia:main-{os_version}-{nv}")),
),
Expand All @@ -116,7 +140,11 @@ impl<'a> Module<'a> {
.stage_name(format!(
"{}{}",
base.unwrap_or("main"),
nvidia_version.map_or_else(String::default, |nv| format!("-{nv}"))
match nvidia {
NvidiaAkmods::Nvidia(nv) if nv => "-nvidia".to_string(),
NvidiaAkmods::Version(nv) if nv > 0 => format!("-nvidia-{nv}"),
_ => String::default(),
}
))
.build()
}
Expand Down