1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
use log::error;
use clap::{command, crate_authors, Args, Parser, Subcommand};
use clap_verbosity_flag::{InfoLevel, Verbosity};
use typed_builder::TypedBuilder;
use crate::{
drivers::types::{BuildDriverType, InspectDriverType},
shadow,
};
pub mod bug_report;
pub mod build;
pub mod completions;
#[cfg(feature = "init")]
pub mod init;
pub mod local;
pub mod template;
pub trait BlueBuildCommand {
/// Runs the command and returns a result
/// of the execution
///
/// # Errors
/// Can return an `anyhow` Error
fn try_run(&mut self) -> anyhow::Result<()>;
/// Runs the command and exits if there is an error.
fn run(&mut self) {
if let Err(e) = self.try_run() {
error!("{e}");
std::process::exit(1);
}
}
}
#[derive(Parser, Debug)]
#[clap(
name = "BlueBuild",
about,
long_about = None,
author=crate_authors!(),
version=shadow::PKG_VERSION,
long_version=shadow::CLAP_LONG_VERSION,
)]
pub struct BlueBuildArgs {
#[command(subcommand)]
pub command: CommandArgs,
#[clap(flatten)]
pub verbosity: Verbosity<InfoLevel>,
}
#[derive(Debug, Subcommand)]
pub enum CommandArgs {
/// Build an image from a recipe
Build(build::BuildCommand),
/// Generate a Containerfile from a recipe
Template(template::TemplateCommand),
/// Upgrade your current OS with the
/// local image saved at `/etc/bluebuild/`.
///
/// This requires having rebased already onto
/// a local archive already by using the `rebase`
/// subcommand.
///
/// NOTE: This can only be used if you have `rpm-ostree`
/// installed. This image will not be signed.
#[command(visible_alias("update"))]
Upgrade(local::UpgradeCommand),
/// Rebase your current OS onto the image
/// being built.
///
/// This will create a tarball of your image at
/// `/etc/bluebuild/` and invoke `rpm-ostree` to
/// rebase onto the image using `oci-archive`.
///
/// NOTE: This can only be used if you have `rpm-ostree`
/// installed. This image will not be signed.
Rebase(local::RebaseCommand),
/// Initialize a new Ublue Starting Point repo
#[cfg(feature = "init")]
Init(init::InitCommand),
#[cfg(feature = "init")]
New(init::NewCommand),
/// Create a pre-populated GitHub issue with information about your configuration
BugReport(bug_report::BugReportCommand),
/// Generate shell completions for your shell to stdout
Completions(completions::CompletionsCommand),
}
#[derive(Default, Clone, Copy, Debug, TypedBuilder, Args)]
pub struct DriverArgs {
/// Runs all instructions inside one layer of the final image.
///
/// WARN: This doesn't work with the
/// docker driver as it has been deprecated.
///
/// NOTE: Squash has a performance benefit for
/// podman and buildah when running inside a container.
#[arg(short, long)]
#[builder(default)]
squash: bool,
/// Select which driver to use to build
/// your image.
#[builder(default)]
#[arg(short = 'B', long)]
build_driver: Option<BuildDriverType>,
/// Select which driver to use to inspect
/// images.
#[builder(default)]
#[arg(short = 'I', long)]
inspect_driver: Option<InspectDriverType>,
}