mirror of
https://github.com/imjasonh/krust
synced 2026-07-17 14:35:11 +00:00
Add Cargo.toml-based configuration for base image
- Add support for [package.metadata.krust] in Cargo.toml - Change default base image to cgr.dev/chainguard/static:latest - Add ProjectConfig struct to load project-specific settings - Update documentation and example to show configuration usage - Fix integration tests to explicitly pass directory argument - This is the idiomatic way for Rust build tools to be configured
This commit is contained in:
parent
5d254c7eca
commit
11083dc527
6 changed files with 74 additions and 7 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
|
@ -45,7 +45,7 @@ pub struct RegistryAuth {
|
|||
}
|
||||
|
||||
fn default_base_image() -> String {
|
||||
"gcr.io/distroless/static:nonroot".to_string()
|
||||
"cgr.dev/chainguard/static:latest".to_string()
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
|
|
@ -59,6 +59,14 @@ impl Default for Config {
|
|||
}
|
||||
}
|
||||
|
||||
/// Project-specific configuration from Cargo.toml
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
pub struct ProjectConfig {
|
||||
/// Base image for this project
|
||||
#[serde(rename = "base-image")]
|
||||
pub base_image: Option<String>,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn load() -> anyhow::Result<Self> {
|
||||
if let Some(config_dir) = dirs::config_dir() {
|
||||
|
|
@ -71,4 +79,27 @@ impl Config {
|
|||
}
|
||||
Ok(Config::default())
|
||||
}
|
||||
|
||||
/// Load project-specific configuration from Cargo.toml
|
||||
pub fn load_project_config(project_path: &Path) -> anyhow::Result<ProjectConfig> {
|
||||
let cargo_toml_path = project_path.join("Cargo.toml");
|
||||
if !cargo_toml_path.exists() {
|
||||
return Ok(ProjectConfig::default());
|
||||
}
|
||||
|
||||
let content = std::fs::read_to_string(&cargo_toml_path)?;
|
||||
let value: toml::Value = toml::from_str(&content)?;
|
||||
|
||||
// Look for [package.metadata.krust] section
|
||||
if let Some(metadata) = value
|
||||
.get("package")
|
||||
.and_then(|p| p.get("metadata"))
|
||||
.and_then(|m| m.get("krust"))
|
||||
{
|
||||
let project_config: ProjectConfig = metadata.clone().try_into()?;
|
||||
return Ok(project_config);
|
||||
}
|
||||
|
||||
Ok(ProjectConfig::default())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ mod tests {
|
|||
#[test]
|
||||
fn test_default_config() {
|
||||
let config = Config::default();
|
||||
assert_eq!(config.base_image, "gcr.io/distroless/static:nonroot");
|
||||
assert_eq!(config.base_image, "cgr.dev/chainguard/static:latest");
|
||||
assert!(config.default_registry.is_none());
|
||||
assert!(config.registries.is_empty());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue