Skip to content

Commit

Permalink
wip: continue cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
cilki committed Nov 23, 2023
1 parent 440729c commit 1416632
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 134 deletions.
15 changes: 11 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ members = [
"goldboot-image",
"goldboot-linux",
"goldboot-registry",
"goldboot-repository",
]
3 changes: 3 additions & 0 deletions goldboot-foundry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@ ron = "0.8.1"
png = "0.17.10"
vnc = "0.4.0"
ssh2 = { version = "0.9.4", features = ["vendored-openssl"] }
sha1 = "0.10.6"
hex = "0.4.3"
strum = { version = "0.25.0", features = ["derive"] }

[dev-dependencies]
11 changes: 4 additions & 7 deletions goldboot-foundry/src/fabricators/mod.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
//! This module contains various common provisioners which may be included in
//! image templates. Templates may also specify their own specialized
//! provisioners for specific tasks.
//!
//! A provisioner is simply an operation to be performed on an image.

use crate::ssh::SshConnection;
use std::error::Error;

pub mod ansible;
pub mod exe;
pub mod hostname;
pub mod luks;
pub mod shell;
pub mod timezone;
pub mod unix_account;

pub trait Provisioner {
/// A `Fabricator` performs some custom operation on an image at the very end of
/// the casting process. When the various options in a `Mold` are not sufficient,
/// fabricators can be used to compensate.
pub trait Fabricator {
fn run(&self, ssh: &mut SshConnection) -> Result<(), Box<dyn Error>>;
}
31 changes: 18 additions & 13 deletions goldboot-foundry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ use simple_error::bail;
use std::{error::Error, fmt::Display, thread, time::SystemTime};
use validator::Validate;

// pub mod library;
pub mod fabricators;
pub mod molds;
pub mod ovmf;
pub mod qemu;
pub mod sources;
pub mod ssh;
pub mod vnc;

/// A `Foundry` produces a goldboot image given a configuration.
/// A `Foundry` produces a goldboot image given a raw configuration. This is the
/// central concept in the machinery that creates images.
#[derive(Clone, Serialize, Deserialize, Validate, Default, Debug)]
pub struct Foundry {
/// The image name
Expand Down Expand Up @@ -41,14 +46,23 @@ pub struct Foundry {
pub password: Option<String>,

#[validate(length(min = 1))]
pub alloy: Vec<Template>,
pub alloy: Vec<Element>,

pub source: Option<Source>,

pub mold: Option<Mold>,

#[validate(length(min = 1))]
pub fabricators: Option<Vec<Fabricator>>,

/// The path to an OVMF.fd file
pub ovmf_path: String,

/// Whether screenshots will be generated during the run for debugging
pub record: bool,

/// When set, the run will pause before each step in the boot sequence
pub debug: bool,
}

/// Represents an image build job.
Expand Down Expand Up @@ -198,7 +212,7 @@ impl BuildJob {

/// Represents a template build process. Multiple workers can run in parallel
/// to speed up multiboot configurations.
pub struct BuildWorker {
pub struct FoundryWorker {
/// A general purpose temporary directory for the run
pub tmp: tempfile::TempDir,

Expand All @@ -215,15 +229,6 @@ pub struct BuildWorker {
pub config: BuildConfig,

pub template: Box<dyn BuildTemplate>,

/// The path to an OVMF.fd file
pub ovmf_path: String,

/// Whether screenshots will be generated during the run for debugging
pub record: bool,

/// When set, the run will pause before each step in the boot sequence
pub debug: bool,
}

unsafe impl Send for BuildWorker {}
Expand Down
26 changes: 9 additions & 17 deletions goldboot-foundry/src/molds/arch_linux/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use log::info;
use log::{debug, info};
use serde::{Deserialize, Serialize};
use simple_error::bail;
use std::{
Expand All @@ -7,7 +7,9 @@ use std::{
};
use validator::Validate;

/// This `Mold` produces an Arch Linux image.
use crate::FoundryWorker;

/// This `Mold` produces an [Arch Linux](https://archlinux.org) image.
#[derive(Clone, Serialize, Deserialize, Validate, Debug)]
pub struct ArchLinux {
pub root_password: Option<String>,
Expand All @@ -26,15 +28,7 @@ pub mod sources {
}
}

pub mod installer {
pub struct ArchLinuxInstaller {}

impl Installer for ArchLinuxInstaller {
fn shutdown
}
}

impl Default for ArchLinuxTemplate {
impl Default for ArchLinux {
fn default() -> Self {
Self {
source: None,
Expand All @@ -43,7 +37,7 @@ impl Default for ArchLinuxTemplate {
}
}

impl BuildTemplate for ArchLinuxTemplate {
impl super::Cast for ArchLinux {
fn metadata() -> TemplateMetadata {
TemplateMetadata {
id: TemplateId::ArchLinux,
Expand All @@ -53,9 +47,7 @@ impl BuildTemplate for ArchLinuxTemplate {
}
}

fn build(&self, context: &BuildWorker) -> Result<(), Box<dyn Error>> {
info!("Starting {} build", console::style("ArchLinux").blue());

fn cast(&self, context: &FoundryWorker) -> Result<(), Box<dyn Error>> {
let mut qemuargs = QemuArgs::new(&context);

qemuargs.drive.push(format!(
Expand Down Expand Up @@ -112,7 +104,7 @@ impl BuildTemplate for ArchLinuxTemplate {
}
}

impl PromptMut for ArchLinuxTemplate {
impl PromptMut for ArchLinux {
fn prompt(
&mut self,
config: &BuildConfig,
Expand All @@ -127,7 +119,7 @@ impl PromptMut for ArchLinuxTemplate {
}
}

pub mod provisioners {
pub mod options {
use std::error::Error;

use serde::{Deserialize, Serialize};
Expand Down
72 changes: 0 additions & 72 deletions goldboot-foundry/src/molds/config.rs

This file was deleted.

19 changes: 13 additions & 6 deletions goldboot-foundry/src/molds/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//! Templates are the central concept that make it easy to define images.

use crate::{build::BuildWorker, *};
use serde::{Deserialize, Serialize};
use std::{error::Error, fmt::Display, path::Path};
use strum::EnumIter;

use crate::FoundryWorker;

pub mod arch_linux;

Expand All @@ -17,9 +19,14 @@ pub struct TemplateMetadata {
pub multiboot: bool,
}

pub trait Mold {
/// Build an image from the template.
fn build(&self, context: &BuildWorker) -> Result<(), Box<dyn Error>>;
/// "Casting" is the process of generating an immutable goldboot image from raw
/// configuration data.
///
/// This term comes from metallurgy where casting means to pour molten metal into
/// a mold, producing a solidified object in the shape of the mold.
pub trait Cast {
/// Cast an image from the mold.
fn cast(&self, context: &FoundryWorker) -> Result<(), Box<dyn Error>>;

// ///
// fn metadata() -> TemplateMetadata;
Expand All @@ -29,7 +36,7 @@ pub trait Mold {
/// images.
#[derive(Clone, Serialize, Deserialize, Debug, EnumIter)]
#[serde(tag = "base")]
pub enum Molds {
pub enum Mold {
// AlpineLinux(crate::molds::alpine_linux::AlpineLinux),
ArchLinux(crate::molds::arch_linux::ArchLinux),
// Artix,
Expand Down Expand Up @@ -69,7 +76,7 @@ pub enum Molds {
// Zorin,
}

impl Display for Molds {
impl Display for Mold {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", todo!())
}
Expand Down
7 changes: 4 additions & 3 deletions goldboot-foundry/src/qemu.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{build::BuildWorker, ssh::SshConnection, vnc::VncConnection, Architecture};
use crate::{build::BuildWorker, ssh::SshConnection, vnc::VncConnection};
use goldboot_image::ImageArch;
use log::{debug, info};
use simple_error::bail;
use std::error::Error;
Expand Down Expand Up @@ -193,8 +194,8 @@ impl QemuArgs {
vnc: vec![format!("127.0.0.1:{}", context.vnc_port % 5900)],
vnc_port: context.vnc_port,
exe: match &context.config.arch {
Architecture::amd64 => String::from("qemu-system-x86_64"),
Architecture::arm64 => String::from("qemu-system-aarch64"),
ImageArch::Amd64 => String::from("qemu-system-x86_64"),
ImageArch::Arm64 => String::from("qemu-system-aarch64"),
_ => String::from("qemu-system-x86_64"),
},
usbdevice: vec![],
Expand Down
Loading

0 comments on commit 1416632

Please sign in to comment.