Skip to content

Commit

Permalink
wip: reorganize crates
Browse files Browse the repository at this point in the history
  • Loading branch information
cilki committed Nov 19, 2023
1 parent 91673b4 commit 440729c
Show file tree
Hide file tree
Showing 78 changed files with 314 additions and 318 deletions.
199 changes: 93 additions & 106 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ strip = true
[workspace]
members = [
"goldboot",
"goldboot-build",
"goldboot-foundry",
"goldboot-image",
"goldboot-linux",
"goldboot-registry",
Expand Down
39 changes: 0 additions & 39 deletions examples/ArchLinux/ansible.yml

This file was deleted.

22 changes: 0 additions & 22 deletions examples/ArchLinux/goldboot.json

This file was deleted.

9 changes: 9 additions & 0 deletions examples/SimpleAlloy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Simple Alloy

This example creates a simple "alloy" image which contains Debian and Windows 11.

To generate the image, enter the directory and run:

```sh
goldboot build
```
27 changes: 27 additions & 0 deletions examples/SimpleAlloy/goldboot.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
(
name: "Alloy example",
description: "Example of how to build a simple alloy image",
arch: "x86_64",
size: "256 Gb",
alloy: [
(
source: Iso(
checksum: "sha1:3700a16d4fcabbd29e9a7fbc97da732c4577dc2a",
url: "https://mirrors.edge.kernel.org/archlinux/iso/latest/archlinux-2022.05.01-x86_64.iso",
),
mold: ArchLinux(
hostname: "ExampleArch",
mirrorlist: [
"https://mirrors.edge.kernel.org/archlinux/$repo/os/$arch",
],
root_password: "root",
packages: ["alacritty", "git", "neovim"],
),
),
(
mold: Windows11(
hostname: "ExampleWindows",
),
),
],
)
File renamed without changes.
10 changes: 10 additions & 0 deletions examples/SimpleArchLinux/ansible.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Configure ArchLinux with Ansible.

- hosts: localhost
tasks:
- name: Update package cache
pacman:
update_cache: yes
upgrade: yes

# ...
27 changes: 27 additions & 0 deletions examples/SimpleArchLinux/goldboot.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
(
name: "Arch Linux example",
description: "Example of how to build a simple Arch Linux image",
arch: "x86_64",
size: "16 Gb",
source: Iso (
checksum: "sha1:3700a16d4fcabbd29e9a7fbc97da732c4577dc2a",
url: "https://mirrors.edge.kernel.org/archlinux/iso/latest/archlinux-2022.05.01-x86_64.iso",
),
mold: ArchLinux (
hostname: "ExampleArch",
mirrorlist: [
"https://mirrors.edge.kernel.org/archlinux/$repo/os/$arch"
],
root_password: "root",
packages: [
"alacritty",
"git",
"neovim",
]
),
fabricators: [
Ansible (
playbook: "ansible.yml"
)
]
)
6 changes: 5 additions & 1 deletion goldboot-build/Cargo.toml → goldboot-foundry/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "goldboot-build"
name = "goldboot-foundry"
description = "Support for building goldboot images"
version = "0.0.1"
edition = "2021"
Expand All @@ -17,5 +17,9 @@ serde = { version = "1.0.190", features = ["derive"] }
simple-error = "0.3.0"
rand = "0.8.5"
goldboot-image = { path="../goldboot-image", version = "0.0.1" }
ron = "0.8.1"
png = "0.17.10"
vnc = "0.4.0"
ssh2 = { version = "0.9.4", features = ["vendored-openssl"] }

[dev-dependencies]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
89 changes: 16 additions & 73 deletions goldboot-build/src/lib.rs → goldboot-foundry/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
use goldboot_image::{ImageHandle, qcow::Qcow3}
use crate::{
library::ImageLibrary,
templates::{BuildTemplate, Template},
};
use goldboot_image::{qcow::Qcow3, ImageArch, ImageHandle};
use log::{debug, info};
use molds::Mold;
use rand::Rng;
use serde::{Deserialize, Serialize};
use simple_error::bail;

Check warning on line 6 in goldboot-foundry/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build Linux

unused import: `simple_error::bail`
use std::{error::Error, thread, time::SystemTime, fmt::Display};
use std::{error::Error, fmt::Display, thread, time::SystemTime};
use validator::Validate;

// pub mod library;
pub mod templates;
pub mod molds;
pub mod ovmf;


/// The global configuration
/// A `Foundry` produces a goldboot image given a configuration.
#[derive(Clone, Serialize, Deserialize, Validate, Default, Debug)]
pub struct BuildConfig {
pub struct Foundry {
/// The image name
#[validate(length(min = 1, max = 64))]
pub name: String,
Expand All @@ -29,7 +25,7 @@ pub struct BuildConfig {

/// The system architecture
#[serde(flatten)]
pub arch: Architecture,
pub arch: ImageArch,

/// The amount of memory to allocate to the VM
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -45,7 +41,14 @@ pub struct BuildConfig {
pub password: Option<String>,

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

pub source: Option<Source>,

pub mold: Option<Mold>,

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

/// Represents an image build job.
Expand Down Expand Up @@ -102,27 +105,7 @@ impl BuildJob {
// Unpack included firmware
let ovmf_path = tmp.path().join("OVMF.fd").to_string_lossy().to_string();

match &self.config.arch {
Architecture::amd64 => {
std::fs::write(
&ovmf_path,
zstd::decode_all(std::io::Cursor::new(OVMF_X86_64))?,
)?;
}
Architecture::i386 => {
std::fs::write(
&ovmf_path,
zstd::decode_all(std::io::Cursor::new(OVMF_I386))?,
)?;
}
Architecture::arm64 => {
std::fs::write(
&ovmf_path,
zstd::decode_all(std::io::Cursor::new(OVMF_AARCH64))?,
)?;
}
_ => bail!("Unsupported architecture"),
}
crate::ovmf::write_to(&self.config.arch, &ovmf_path)?;

Ok(BuildWorker {
tmp,
Expand Down Expand Up @@ -262,43 +245,3 @@ impl BuildWorker {
Ok(())
}
}

/// Represents a system architecture.
#[derive(Clone, Copy, Serialize, Deserialize, Debug, PartialEq, Eq, EnumIter, Display)]
#[serde(tag = "arch")]
pub enum Architecture {
Amd64,
Arm64,
I386,
Mips,
Mips64,
S390x,
}

impl Default for Architecture {
fn default() -> Self {
match std::env::consts::ARCH {
"x86" => Architecture::I386,
"x86_64" => Architecture::Amd64,
"aarch64" => Architecture::Arm64,
"mips" => Architecture::Mips,
"mips64" => Architecture::Mips64,
"s390x" => Architecture::S390x,
_ => panic!("Unknown CPU architecture"),
}
}
}

impl TryFrom<String> for Architecture {
type Error = Box<dyn Error>;
fn try_from(s: String) -> Result<Self, Self::Error> {
match s.to_lowercase().as_str() {
"amd64" => Ok(Architecture::amd64),
"x86_64" => Ok(Architecture::amd64),
"arm64" => Ok(Architecture::arm64),
"aarch64" => Ok(Architecture::arm64),
"i386" => Ok(Architecture::i386),
_ => bail!("Unknown architecture"),
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::{build::BuildWorker, provisioners::*, qemu::QemuArgs, templates::*};
use log::info;
use serde::{Deserialize, Serialize};
use simple_error::bail;
Expand All @@ -8,11 +7,12 @@ use std::{
};
use validator::Validate;

/// This `Mold` produces an Arch Linux image.
#[derive(Clone, Serialize, Deserialize, Validate, Debug)]
pub struct ArchLinuxTemplate {
pub source: sources::ArchSource,
pub installer: installer::ArchLinuxInstaller,
pub provisioners: Option<Vec<provisioners::ArchProvisioner>>,
pub struct ArchLinux {
pub root_password: Option<String>,
pub packages: Option<Vec<String>>,
pub mirrorlist: Option<Vec<String>>,
}

pub mod sources {
Expand All @@ -26,6 +26,14 @@ pub mod sources {
}
}

pub mod installer {
pub struct ArchLinuxInstaller {}

impl Installer for ArchLinuxInstaller {
fn shutdown

Check failure on line 33 in goldboot-foundry/src/molds/arch_linux/mod.rs

View workflow job for this annotation

GitHub Actions / Build Linux

missing parameters for function definition

Check failure on line 33 in goldboot-foundry/src/molds/arch_linux/mod.rs

View workflow job for this annotation

GitHub Actions / Build Linux

associated function in `impl` without body
}

Check failure on line 34 in goldboot-foundry/src/molds/arch_linux/mod.rs

View workflow job for this annotation

GitHub Actions / Build Linux

expected one of `->`, `<`, `where`, or `{`, found `}`
}

impl Default for ArchLinuxTemplate {
fn default() -> Self {
Self {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
Loading

0 comments on commit 440729c

Please sign in to comment.