Add a prerequisites check
This commit is contained in:
parent
6fa97f2e4a
commit
4bb04c7a98
44
Cargo.lock
generated
44
Cargo.lock
generated
@ -61,7 +61,7 @@ version = "1.0.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648"
|
checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-sys",
|
"windows-sys 0.52.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -71,7 +71,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7"
|
checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anstyle",
|
"anstyle",
|
||||||
"windows-sys",
|
"windows-sys 0.52.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -341,7 +341,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245"
|
checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"windows-sys",
|
"windows-sys 0.52.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -405,6 +405,7 @@ dependencies = [
|
|||||||
"serde_yaml",
|
"serde_yaml",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"time",
|
"time",
|
||||||
|
"which",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -413,6 +414,15 @@ version = "0.3.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7"
|
checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "home"
|
||||||
|
version = "0.5.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5"
|
||||||
|
dependencies = [
|
||||||
|
"windows-sys 0.52.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "humantime"
|
name = "humantime"
|
||||||
version = "2.1.0"
|
version = "2.1.0"
|
||||||
@ -460,7 +470,7 @@ checksum = "0bad00257d07be169d870ab665980b06cdb366d792ad690bf2e76876dc503455"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"hermit-abi",
|
"hermit-abi",
|
||||||
"rustix",
|
"rustix",
|
||||||
"windows-sys",
|
"windows-sys 0.52.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -664,7 +674,7 @@ dependencies = [
|
|||||||
"errno",
|
"errno",
|
||||||
"libc",
|
"libc",
|
||||||
"linux-raw-sys",
|
"linux-raw-sys",
|
||||||
"windows-sys",
|
"windows-sys 0.52.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -779,7 +789,7 @@ dependencies = [
|
|||||||
"fastrand",
|
"fastrand",
|
||||||
"redox_syscall",
|
"redox_syscall",
|
||||||
"rustix",
|
"rustix",
|
||||||
"windows-sys",
|
"windows-sys 0.52.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -940,6 +950,19 @@ version = "0.2.89"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f"
|
checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "which"
|
||||||
|
version = "5.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9bf3ea8596f3a0dd5980b46430f2058dfe2c36a27ccfbb1845d6fbfcd9ba6e14"
|
||||||
|
dependencies = [
|
||||||
|
"either",
|
||||||
|
"home",
|
||||||
|
"once_cell",
|
||||||
|
"rustix",
|
||||||
|
"windows-sys 0.48.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winapi"
|
name = "winapi"
|
||||||
version = "0.3.9"
|
version = "0.3.9"
|
||||||
@ -980,6 +1003,15 @@ dependencies = [
|
|||||||
"windows-targets 0.52.0",
|
"windows-targets 0.52.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-sys"
|
||||||
|
version = "0.48.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
|
||||||
|
dependencies = [
|
||||||
|
"windows-targets 0.48.5",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-sys"
|
name = "windows-sys"
|
||||||
version = "0.52.0"
|
version = "0.52.0"
|
||||||
|
@ -21,3 +21,4 @@ serde_json = "1.0.110"
|
|||||||
serde_yaml = "0.9.29"
|
serde_yaml = "0.9.29"
|
||||||
tempfile = "3.9.0"
|
tempfile = "3.9.0"
|
||||||
time = { version = "0.3.31", features = ["serde", "formatting", "parsing"]}
|
time = { version = "0.3.31", features = ["serde", "formatting", "parsing"]}
|
||||||
|
which = "5.0.0"
|
||||||
|
@ -189,11 +189,9 @@ impl Chart {
|
|||||||
return Err(Box::from("unknown repository kind is found"));
|
return Err(Box::from("unknown repository kind is found"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
None => Err(Box::from(
|
||||||
Err(Box::from(
|
"repository object is not filled up for the chart",
|
||||||
"repository object is not filled up for the chart",
|
)),
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
25
src/main.rs
25
src/main.rs
@ -8,7 +8,7 @@ pub(crate) mod template;
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fs;
|
use std::{env, fs};
|
||||||
use std::{fs::create_dir, path::PathBuf, process::exit};
|
use std::{fs::create_dir, path::PathBuf, process::exit};
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
|
|
||||||
@ -27,6 +27,8 @@ struct Args {
|
|||||||
/// Dry run
|
/// Dry run
|
||||||
#[arg(short, long, default_value = "false")]
|
#[arg(short, long, default_value = "false")]
|
||||||
dry_run: bool,
|
dry_run: bool,
|
||||||
|
#[arg(long, default_value = "false")]
|
||||||
|
skip_prerequisites_check: bool,
|
||||||
/// Init git patch. Use it if you want to create git patch for a chart
|
/// Init git patch. Use it if you want to create git patch for a chart
|
||||||
/// It's going to pull a chart and init a git repo there, so you can
|
/// It's going to pull a chart and init a git repo there, so you can
|
||||||
/// apply changes and create a patch file
|
/// apply changes and create a patch file
|
||||||
@ -36,9 +38,30 @@ struct Args {
|
|||||||
init_git_patch: Option<Vec<String>>,
|
init_git_patch: Option<Vec<String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn check_prerequisites() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
info!("checking prerequisites");
|
||||||
|
let prerequisites = vec!["helm", "yq", "helm"];
|
||||||
|
for bin in prerequisites {
|
||||||
|
info!("checking {}", bin);
|
||||||
|
which::which(bin)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
// Prepare the logger
|
||||||
|
if env::var("RUST_LOG").is_err() {
|
||||||
|
env::set_var("RUST_LOG", "info")
|
||||||
|
}
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
if !args.skip_prerequisites_check {
|
||||||
|
if let Err(err) = check_prerequisites() {
|
||||||
|
error!("{}", err);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
// Prepare the workdir
|
// Prepare the workdir
|
||||||
let workdir_path = match args.workdir {
|
let workdir_path = match args.workdir {
|
||||||
Some(res) => match create_dir(res.clone()) {
|
Some(res) => match create_dir(res.clone()) {
|
||||||
|
@ -36,18 +36,16 @@ pub(crate) struct Version {
|
|||||||
|
|
||||||
pub(crate) fn repo_from_chart(chart: Chart) -> Result<Box<dyn Repo>, Box<dyn std::error::Error>> {
|
pub(crate) fn repo_from_chart(chart: Chart) -> Result<Box<dyn Repo>, Box<dyn std::error::Error>> {
|
||||||
match chart.get_repo_kind() {
|
match chart.get_repo_kind() {
|
||||||
Ok(res) => {
|
Ok(res) => match res {
|
||||||
match res {
|
crate::config::RepositoryKind::Helm => {
|
||||||
crate::config::RepositoryKind::Helm => {
|
let helm: helm::Helm = chart.into();
|
||||||
let helm: helm::Helm = chart.into();
|
Ok(Box::new(helm))
|
||||||
Ok(Box::new(helm))
|
|
||||||
}
|
|
||||||
crate::config::RepositoryKind::Git => {
|
|
||||||
let git: git::Git = chart.into();
|
|
||||||
Ok(Box::new(git))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
crate::config::RepositoryKind::Git => {
|
||||||
|
let git: git::Git = chart.into();
|
||||||
|
Ok(Box::new(git))
|
||||||
|
}
|
||||||
|
},
|
||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user