Skip to content

Commit

Permalink
refactor and begin transition to async
Browse files Browse the repository at this point in the history
  • Loading branch information
koehlma committed Jan 10, 2025
1 parent 10b7aaf commit 05bebda
Show file tree
Hide file tree
Showing 48 changed files with 1,484 additions and 1,297 deletions.
15 changes: 15 additions & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,33 @@
"ENVBLK",
"ENXIO",
"errno",
"Exbibyte",
"exbibytes",
"execv",
"fallocate",
"fcntl",
"fdisk",
"filesystems",
"fstype",
"Gibibyte",
"gibibytes",
"github",
"GPIO",
"GRUBENV",
"Imager",
"indexmap",
"indicatif",
"Kibibyte",
"Kibibytes",
"libc",
"libfdisk",
"libfuzzer",
"linux",
"losetup",
"lowerdir",
"lseek",
"Mebibyte",
"Mebibytes",
"mmap",
"mmcblk",
"mmdebstrap",
Expand All @@ -74,6 +83,8 @@
"partitiontable",
"partprobe",
"PARTUUID",
"Pebibyte",
"pebibytes",
"pieeprom",
"postgresql",
"Qcow",
Expand All @@ -94,19 +105,23 @@
"rustfmt",
"sectorsize",
"sfdisk",
"sidex",
"silitics",
"Silitics",
"Squashfs",
"stlv",
"syscall",
"sysfs",
"Tebibyte",
"tebibytes",
"tempdir",
"tmpfs",
"tryboot",
"uboot",
"UEFI",
"uguid",
"ulonglong",
"underflows",
"unistd",
"upperdir",
"uuid",
Expand Down
17 changes: 10 additions & 7 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ tracing = "0.1"
sidex = { git = "https://github.com/silitics/sidex.git" }
sidex-build-rs = { git = "https://github.com/silitics/sidex.git" }
sidex-serde = { git = "https://github.com/silitics/sidex.git" }
xscript = "0.3.0"
xscript = { version = "0.4.0", features = ["tokio"] }

# Colocated but not Rugix-specific crates.
byte-calc = { path = "crates/byte-calc", features = ["serde"] }
Expand Down
2 changes: 1 addition & 1 deletion bakery/repositories/core/recipes/ssh/steps/01-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ if [ "${RECIPE_PARAM_ROOT_AUTHORIZED_KEYS}" != "" ]; then
mkdir -p /root/.ssh
echo "${RECIPE_PARAM_ROOT_AUTHORIZED_KEYS}" >> /root/.ssh/authorized_keys
chmod -R 600 /root/.ssh
cat /root/.ssh/authorized_keys >&2
cat /root/.ssh/authorized_keys
fi
2 changes: 1 addition & 1 deletion crates/rugpi-bakery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ serde = { version = "1.0.171", features = ["derive", "rc"] }
sha1 = "0.10.5"
tempfile = "3.8.1"
thiserror = "1.0.43"
tokio = { version = "1.42.0", features = ["full"] }
toml = "0.8.8"
url = { version = "2.4.0", features = ["serde"] }
uuid = { version = "1.8.0", features = ["v4"] }
xscript.workspace = true
tracing.workspace = true
tokio.workspace = true

reportify.workspace = true
rugpi-cli.workspace = true
Expand Down
1 change: 1 addition & 0 deletions crates/rugpi-bakery/schemas/images.sidex
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ record ImageLayout {

/// Partition table type.
#[json(tagged=externally, rename_all = "lowercase")]
#[rust(derive(Copy))]
variant PartitionTableType {
/// MBR partition.
Mbr,
Expand Down
1 change: 1 addition & 0 deletions crates/rugpi-bakery/schemas/projects.sidex
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ record ProjectConfig {
/// Architecture.
#[json(rename_all = "lowercase")]
#[json(tagged=externally)]
#[rust(derive(Copy, PartialEq, Eq, Hash))]
variant Architecture {
/// 64-bit x86.
Amd64,
Expand Down
5 changes: 5 additions & 0 deletions crates/rugpi-bakery/schemas/repositories.sidex
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ record RepositoryConfig {
}

/// Repository source.
#[rust(derive(PartialEq, Eq))]
#[json(tagged=implicitly)]
variant SourceConfig {
/// Repository is an external Git repository.
Expand All @@ -20,19 +21,23 @@ variant SourceConfig {
}

/// Git repository source.
#[rust(derive(PartialEq, Eq))]
record GitSourceConfig {
/// URL of the Git repository.
#[json(name = "git")]
url: string,
/// Specific tag of the Git repository.
tag?: string,
/// Specific branch of the Git repository.
branch?: string,
/// Specific revision of the Git repository.
rev?: string,
/// Subdirectory in which the repository is located.
dir?: string,
}

/// Local repository source.
#[rust(derive(PartialEq, Eq))]
record PathSourceConfig {
/// Path of the repository relative to the project directory.
path: string,
Expand Down
14 changes: 0 additions & 14 deletions crates/rugpi-bakery/src/bake/targets/mod.rs

This file was deleted.

88 changes: 88 additions & 0 deletions crates/rugpi-bakery/src/cli/args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//! Definition of the command line arguments.
use std::path::PathBuf;

use clap::Parser;

use crate::config::projects::Architecture;

/// Command line arguments.
#[derive(Debug, Parser)]
#[command(author, about = None, long_about = None)]
pub struct Args {
/// Path to the `rugix-bakery.toml` configuration file.
#[clap(long)]
pub config: Option<PathBuf>,
/// The command to execute.
#[clap(subcommand)]
pub cmd: Command,
}

/// Commands of the CLI.
#[derive(Debug, Parser)]
pub enum Command {
/// Bake an image or a layer.
#[clap(subcommand)]
Bake(BakeCommand),
/// Run integration tests.
Test(TestCommand),
/// List images, recipes, and layers.
#[clap(subcommand)]
List(ListCommand),
/// Pull in external repositories.
Pull,
/// Initialize the project from a template.
Init(InitCommand),
/// Spawn a shell in the Rugpi Bakery Docker container.
Shell,
}

/// The `list` command.
#[derive(Debug, Parser)]
pub enum ListCommand {
/// List available images.
Images,
}

/// The `bake` command.
#[derive(Debug, Parser)]
pub enum BakeCommand {
/// Bake an image.
Image {
/// The name of the image to bake.
image: String,
/// The output path of the resulting image.
output: Option<PathBuf>,
},
/// Bake a layer.
Layer {
/// The architecture to bake the layer for.
#[clap(long)]
arch: Architecture,
/// The name of the layer to bake.
layer: String,
},
}

/// The `test` command.
#[derive(Debug, Parser)]
pub struct TestCommand {
pub workflows: Vec<String>,
}

/// The `bake` command.
#[derive(Debug, Parser)]
pub enum InternalCommand {
MakeImage {
config: PathBuf,
source: PathBuf,
image: PathBuf,
},
}

/// The `init` command.
#[derive(Debug, Parser)]
pub struct InitCommand {
/// Template to use.
pub template: Option<String>,
}
6 changes: 6 additions & 0 deletions crates/rugpi-bakery/src/cli/cmds/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pub mod run_bake;
pub mod run_init;
pub mod run_list;
pub mod run_pull;
pub mod run_shell;
pub mod run_test;
24 changes: 24 additions & 0 deletions crates/rugpi-bakery/src/cli/cmds/run_bake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//! The `bake` command.
use std::path::Path;

use crate::cli::{args, load_project};
use crate::oven::LayerBakery;
use crate::{oven, BakeryResult};

/// Run the `bake` command.
pub async fn run(args: &args::Args, cmd: &args::BakeCommand) -> BakeryResult<()> {
let project = load_project(args).await?;
match cmd {
args::BakeCommand::Image { image, output } => {
let output = output
.clone()
.unwrap_or_else(|| Path::new("build/images").join(image).with_extension("img"));
oven::bake_image(&project, image, &output).await?;
}
args::BakeCommand::Layer { layer, arch } => {
LayerBakery::new(&project, *arch).bake_root(layer).await?;
}
}
Ok(())
}
Loading

0 comments on commit 05bebda

Please sign in to comment.