Skip to content

Commit

Permalink
noop out builder code for now, working on manifest parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
korewaChino committed Oct 4, 2024
1 parent d5d8fb6 commit 7d2aff2
Show file tree
Hide file tree
Showing 5 changed files with 325 additions and 13 deletions.
16 changes: 16 additions & 0 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Katsu-NG architecture

Katsu-NG (v2) is a complete rewrite of the original Katsu. It's a meta-buildsystem for operating system images, designed to be robust and flexible.

## Design goals

- **Declarative**: The user should be able to describe the desired state of the image, and Katsu should figure out how to get there.
- **Extensible**: Katsu should be able to support a wide variety of build systems and image formats.
- **Cacheable**: Katsu should be able to cache intermediate build artifacts to speed up the build process.

## Objects

Katsu-NG has a few core objects that it uses to represent the state of the image:

- **Target**: A target is a single output that Katsu is trying to build. For example, a target might be a disk image, a kernel, or a bootloader.
-
22 changes: 16 additions & 6 deletions src/cfg/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ dyn_clone::clone_trait_object!(BootstrapOption);
#[derive(Deserialize, Debug, Clone, Serialize)]
pub struct Manifest {
/// Builder type
#[serde(default)]
pub builder: BuilderType,
/// The distro name for the build result
// entrypoint must have a distro name
Expand Down Expand Up @@ -83,6 +84,7 @@ pub struct Manifest {
#[serde(default)]
pub iso: Option<IsoConfig>,

#[serde(default)]
pub bootloader: super::boot::Bootloader,
}

Expand All @@ -92,6 +94,10 @@ impl Manifest {
self.iso.as_ref().map_or(DEFAULT_VOLID, |iso| &iso.volume_id)
}
/// Load manifest from file
///
/// # Errors
///
/// This function will return an error if the file cannot be read or parsed.
pub fn load(path: &Path) -> color_eyre::Result<Self> {
Ok(hcl::de::from_body(ensan::parse(std::fs::read_to_string(path)?)?)?)
}
Expand Down Expand Up @@ -122,8 +128,10 @@ pub enum BootstrapMethod {
}

#[derive(Deserialize, Debug, Clone, Serialize)]
#[serde(rename_all = "snake_case")]
#[serde(tag = "type")]
pub struct PartitionLayout {

Check failure on line 133 in src/cfg/manifest.rs

View workflow job for this annotation

GitHub Actions / Clippy

found empty brackets on struct declaration
pub partition: Vec<Partition>,
// pub partition: Vec<Partition>,
}

#[derive(Deserialize, Debug, Clone, Serialize)]
Expand All @@ -142,22 +150,24 @@ pub struct CopyFiles {
pub destination: String,
}

/// A Katsu output
/// A Katsu target
///
/// Represented by a HCL block `output`
/// Represented by a HCL block `target`
///
/// ```hcl
/// output "type" "id" {}
/// output "type" "id" {
/// method = "oci"
/// }
/// ```
// todo: evaluate dep graph for outputs, so we can build them in the correct order
#[derive(Debug, Clone, Serialize)]
#[serde(tag = "type")]
// an output can be a filesystem, a container image, or a disk image.
// It can also rely on other outputs for bootstrapping.
pub struct Output {
pub struct Target {
pub id: String,
/// Method to bootstrap the output filesystem
pub bootstrap_method: BootstrapMethod,
pub method: BootstrapMethod,
/// Copy files from the host to the output tree before packing
pub copy: Vec<CopyFiles>,
/// Scripts to run before and after the build
Expand Down
12 changes: 7 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ pub struct KatsuCli {
/// Config file location
config: PathBuf,

#[arg(short, long, value_parser = value_parser!(OutputFormat))]
output: OutputFormat,
// #[arg(short, long, value_parser = value_parser!(OutputFormat))]
// output: OutputFormat,
#[arg(short, long,env = "KATSU_SKIP_PHASES", value_parser = value_parser!(SkipPhases), default_value = "")]
skip_phases: SkipPhases,

Expand Down Expand Up @@ -122,10 +122,12 @@ fn main() -> color_eyre::Result<()> {

trace!(?manifest, "Loaded manifest");

let builder = builder::KatsuBuilder::new(manifest, cli.output, cli.skip_phases);
println!("Loaded manifest:\n{manifest:#?}");

tracing::info!("Building image");
builder.build()?;
// let builder = builder::KatsuBuilder::new(manifest, cli.output, cli.skip_phases);

// tracing::info!("Building image");
// builder.build()?;

Ok(())
}
4 changes: 2 additions & 2 deletions tests/main.katsu.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ output "disk" "xfce" {
}
}
}
partition_layout = {
partition_layout {
// layout here, partno is sorted by order of appearance
// the table here will be then passed to a respective partitioning table
// structure (i.e Partition for disks, Iso9660, etc.)
Expand Down Expand Up @@ -265,7 +265,7 @@ output "iso" "xfce" {

// We do not mount ISO files like a rootfs, so we will be using the custom URI paths scheme

partition_layout = {
partition_layout {
partition {
// partno is used, label may not be included in the resulting ISO
// We can use the label to refer to the partition in the copy_files directive
Expand Down
Loading

0 comments on commit 7d2aff2

Please sign in to comment.