Implement git commit hash tracking for build display
All checks were successful
Build and Release / build-and-release (push) Successful in 1m24s

- Add get_git_commit() method to read /var/lib/cm-dashboard/git-commit
- Replace NixOS build version with actual git commit hash
- Show deployed commit hash as 'Build:' value for accurate tracking
- Enable verification of which exact commit is deployed per host
- Update version to 0.1.42
This commit is contained in:
Christoffer Martinsson 2025-10-29 15:29:02 +01:00
parent fc6b3424cf
commit c8f800a1e5
5 changed files with 27 additions and 11 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "cm-dashboard-agent"
version = "0.1.41"
version = "0.1.42"
edition = "2021"
[dependencies]

View File

@ -37,6 +37,22 @@ impl NixOSCollector {
}
/// Get configuration hash from deployed nix store system
/// Get git commit hash from rebuild process
fn get_git_commit(&self) -> Result<String, Box<dyn std::error::Error>> {
let commit_file = "/var/lib/cm-dashboard/git-commit";
match std::fs::read_to_string(commit_file) {
Ok(content) => {
let commit_hash = content.trim();
if commit_hash.len() >= 7 {
Ok(commit_hash.to_string())
} else {
Err("Git commit hash too short".into())
}
}
Err(e) => Err(format!("Failed to read git commit file: {}", e).into())
}
}
fn get_config_hash(&self) -> Result<String, Box<dyn std::error::Error>> {
// Read the symlink target of /run/current-system to get nix store path
let output = Command::new("readlink")
@ -74,25 +90,25 @@ impl Collector for NixOSCollector {
let mut metrics = Vec::new();
let timestamp = chrono::Utc::now().timestamp() as u64;
// Collect NixOS build information (config hash)
match self.get_config_hash() {
Ok(config_hash) => {
// Collect git commit information (shows what's actually deployed)
match self.get_git_commit() {
Ok(git_commit) => {
metrics.push(Metric {
name: "system_nixos_build".to_string(),
value: MetricValue::String(config_hash),
value: MetricValue::String(git_commit),
unit: None,
description: Some("NixOS deployed configuration hash".to_string()),
description: Some("Git commit hash of deployed configuration".to_string()),
status: Status::Ok,
timestamp,
});
}
Err(e) => {
debug!("Failed to get config hash: {}", e);
debug!("Failed to get git commit: {}", e);
metrics.push(Metric {
name: "system_nixos_build".to_string(),
value: MetricValue::String("unknown".to_string()),
unit: None,
description: Some("NixOS config hash (failed to detect)".to_string()),
description: Some("Git commit hash (failed to detect)".to_string()),
status: Status::Unknown,
timestamp,
});

View File

@ -1,6 +1,6 @@
[package]
name = "cm-dashboard"
version = "0.1.41"
version = "0.1.42"
edition = "2021"
[dependencies]

View File

@ -14,7 +14,7 @@ use app::Dashboard;
/// Get hardcoded version
fn get_version() -> &'static str {
"v0.1.41"
"v0.1.42"
}
/// Check if running inside tmux session

View File

@ -1,6 +1,6 @@
[package]
name = "cm-dashboard-shared"
version = "0.1.41"
version = "0.1.42"
edition = "2021"
[dependencies]