chore: Switch to using my new proc_macro comlexr

This commit is contained in:
Gerald Pinder 2025-01-11 16:10:03 -05:00
parent 796ff4869b
commit cbb6efd14d
18 changed files with 208 additions and 352 deletions

View file

@ -1,7 +1,8 @@
use std::{io::Write, process::Stdio};
use blue_build_utils::{cmd, credentials::Credentials};
use blue_build_utils::credentials::Credentials;
use colored::Colorize;
use comlexr::cmd;
use log::{debug, error, info, trace};
use miette::{bail, miette, IntoDiagnostic, Result};
use semver::Version;

View file

@ -1,11 +1,11 @@
use std::{fmt::Debug, fs, io::Write, path::Path, process::Stdio};
use blue_build_utils::{
cmd,
constants::{COSIGN_PASSWORD, COSIGN_PUB_PATH, COSIGN_YES},
credentials::Credentials,
};
use colored::Colorize;
use comlexr::cmd;
use log::{debug, trace};
use miette::{bail, miette, Context, IntoDiagnostic, Result};
@ -27,10 +27,13 @@ impl SigningDriver for CosignDriver {
let mut command = cmd!(
"cosign",
"generate-key-pair",
COSIGN_PASSWORD => "",
COSIGN_YES => "true",
// COSIGN_PASSWORD => "",
// COSIGN_YES => "true",
);
command.current_dir(path);
command
.current_dir(path)
.env(COSIGN_PASSWORD, "")
.env(COSIGN_YES, "true");
let status = command.status().into_diagnostic()?;
@ -49,9 +52,10 @@ impl SigningDriver for CosignDriver {
"cosign",
"public-key",
format!("--key={priv_key}"),
COSIGN_PASSWORD => "",
COSIGN_YES => "true",
// COSIGN_PASSWORD => "",
// COSIGN_YES => "true",
);
command.env(COSIGN_PASSWORD, "").env(COSIGN_YES, "true");
trace!("{command:?}");
let output = command.output().into_diagnostic()?;
@ -93,10 +97,11 @@ impl SigningDriver for CosignDriver {
username,
"--password-stdin",
registry,
stdin = Stdio::piped(),
stdout = Stdio::piped(),
stderr = Stdio::piped(),
);
command
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped());
trace!("{command:?}");
let mut child = command.spawn().into_diagnostic()?;
@ -135,9 +140,10 @@ impl SigningDriver for CosignDriver {
if let Some(ref key) = opts.key => format!("--key={key}"),
"--recursive",
opts.image.to_string(),
COSIGN_PASSWORD => "",
COSIGN_YES => "true",
// COSIGN_PASSWORD => "",
// COSIGN_YES => "true",
);
command.env(COSIGN_PASSWORD, "").env(COSIGN_YES, "true");
trace!("{command:?}");
if !command.status().into_diagnostic()?.success() {
@ -151,17 +157,14 @@ impl SigningDriver for CosignDriver {
let mut command = cmd!(
"cosign",
"verify",
|c| {
match &opts.verify_type {
VerifyType::File(path) => cmd!(c, format!("--key={}", path.display())),
VerifyType::Keyless { issuer, identity } => cmd!(
c,
"--certificate-identity-regexp",
identity as &str,
"--certificate-oidc-issuer",
issuer as &str,
),
};
match &opts.verify_type {
VerifyType::File(path) => format!("--key={}", path.display()),
VerifyType::Keyless { issuer, identity } => [
"--certificate-identity-regexp",
&**identity,
"--certificate-oidc-issuer",
&**issuer,
],
},
opts.image.to_string(),
);

View file

@ -7,13 +7,13 @@ use std::{
};
use blue_build_utils::{
cmd,
constants::{BB_BUILDKIT_CACHE_GHA, CONTAINER_FILE, DOCKER_HOST, GITHUB_ACTIONS},
credentials::Credentials,
string_vec,
};
use cached::proc_macro::cached;
use colored::Colorize;
use comlexr::cmd;
use log::{debug, info, trace, warn};
use miette::{bail, miette, IntoDiagnostic, Result};
use once_cell::sync::Lazy;
@ -204,10 +204,11 @@ impl BuildDriver for DockerDriver {
username,
"--password-stdin",
registry,
stdin = Stdio::piped(),
stdout = Stdio::piped(),
stderr = Stdio::piped(),
);
command
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped());
trace!("{command:?}");
let mut child = command.spawn().into_diagnostic()?;
@ -253,17 +254,18 @@ impl BuildDriver for DockerDriver {
});
let buildx = scope.spawn(|| {
let run_setup = !env::var(DOCKER_HOST).is_ok_and(|dh| !dh.is_empty());
if run_setup {
Self::setup()?;
}
cmd!(
"docker",
"buildx",
"prune",
"--force",
|command|? {
if !env::var(DOCKER_HOST).is_ok_and(|dh| !dh.is_empty()) {
Self::setup()?;
cmd!(command, "--builder=bluebuild");
}
},
if run_setup => "--builder=bluebuild",
if opts.all => "--all",
)
.message_status("docker buildx prune", "Pruning Docker Buildx")
@ -293,16 +295,58 @@ impl BuildDriver for DockerDriver {
warn!("Squash is deprecated for docker so this build will not squash");
}
let mut command = cmd!(
let run_setup = !env::var(DOCKER_HOST).is_ok_and(|dh| !dh.is_empty());
if run_setup {
Self::setup()?;
}
let final_images = match (opts.image, opts.archive_path.as_deref()) {
(Some(image), None) => {
let images = if opts.tags.is_empty() {
let image = image.to_string();
string_vec![image]
} else {
opts.tags
.iter()
.map(|tag| {
format!("{}/{}:{tag}", image.resolve_registry(), image.repository())
})
.collect()
};
images
}
(None, Some(archive_path)) => {
string_vec![archive_path.display().to_string()]
}
(Some(_), Some(_)) => bail!("Cannot use both image and archive path"),
(None, None) => bail!("Need either the image or archive path set"),
};
let first_image = final_images.first().unwrap();
let command = cmd!(
"docker",
"buildx",
|command|? {
if !env::var(DOCKER_HOST).is_ok_and(|dh| !dh.is_empty()) {
Self::setup()?;
cmd!(command, "--builder=bluebuild");
}
},
if run_setup => "--builder=bluebuild",
"build",
".",
match (opts.image, opts.archive_path.as_deref()) {
(Some(_), None) if opts.push => [
"--output",
format!(
"type=image,name={first_image},push=true,compression={},oci-mediatypes=true",
opts.compression
),
],
(Some(_), None) if env::var(GITHUB_ACTIONS).is_err() => "--load",
(None, Some(archive_path)) => [
"--output",
format!("type=oci,dest={}", archive_path.display()),
],
_ => [],
},
"--pull",
if !matches!(opts.platform, Platform::Native) => [
"--platform",
@ -320,73 +364,19 @@ impl BuildDriver for DockerDriver {
],
);
let final_images = match (opts.image, opts.archive_path.as_deref()) {
(Some(image), None) => {
let images = if opts.tags.is_empty() {
let image = image.to_string();
cmd!(command, "-t", &image);
string_vec![image]
} else {
opts.tags.iter().for_each(|tag| {
cmd!(
command,
"-t",
format!("{}/{}:{tag}", image.resolve_registry(), image.repository())
);
});
opts.tags
.iter()
.map(|tag| {
format!("{}/{}:{tag}", image.resolve_registry(), image.repository())
})
.collect()
};
let first_image = images.first().unwrap();
if opts.push {
cmd!(
command,
"--output",
format!(
"type=image,name={first_image},push=true,compression={},oci-mediatypes=true",
opts.compression
),
);
// We don't want to load the image into docker as it will double disk usage
} else if env::var(GITHUB_ACTIONS).is_err() {
cmd!(command, "--load");
}
images
}
(None, Some(archive_path)) => {
cmd!(
command,
"--output",
format!("type=oci,dest={}", archive_path.display())
);
string_vec![archive_path.display().to_string()]
}
(Some(_), Some(_)) => bail!("Cannot use both image and archive path"),
(None, None) => bail!("Need either the image or archive path set"),
};
let display_image = final_images.first().unwrap(); // There will always be at least one image
cmd!(command, ".");
trace!("{command:?}");
if command
.build_status(display_image, "Building Image")
.build_status(first_image, "Building Image")
.into_diagnostic()?
.success()
{
if opts.push {
info!("Successfully built and pushed image {}", display_image);
info!("Successfully built and pushed image {}", first_image);
} else {
info!("Successfully built image {}", display_image);
info!("Successfully built image {}", first_image);
}
} else {
bail!("Failed to build image {}", display_image);
bail!("Failed to build image {}", first_image);
}
Ok(final_images)
}
@ -408,15 +398,16 @@ fn get_metadata_cache(opts: &GetMetadataOpts) -> Result<ImageMetadata> {
trace!("DockerDriver::get_metadata({opts:#?})");
let image_str = opts.image.to_string();
let run_setup = !env::var(DOCKER_HOST).is_ok_and(|dh| !dh.is_empty());
if run_setup {
DockerDriver::setup()?;
}
let mut command = cmd!(
"docker",
"buildx",
|command|? {
if !env::var(DOCKER_HOST).is_ok_and(|dh| !dh.is_empty()) {
DockerDriver::setup()?;
cmd!(command, "--builder=bluebuild");
}
},
if run_setup => "--builder=bluebuild",
"imagetools",
"inspect",
"--format",

View file

@ -1,6 +1,7 @@
use std::path::PathBuf;
use blue_build_utils::{cmd, string_vec};
use blue_build_utils::string_vec;
use comlexr::cmd;
use log::trace;
use super::{opts::GenerateTagsOpts, CiDriver, Driver};

View file

@ -6,9 +6,10 @@ use std::{
time::Duration,
};
use blue_build_utils::{cmd, credentials::Credentials};
use blue_build_utils::credentials::Credentials;
use cached::proc_macro::cached;
use colored::Colorize;
use comlexr::cmd;
use indicatif::{ProgressBar, ProgressStyle};
use log::{debug, error, info, trace};
use miette::{bail, miette, IntoDiagnostic, Report, Result};

View file

@ -1,8 +1,8 @@
use std::{process::Stdio, time::Duration};
use blue_build_utils::cmd;
use cached::proc_macro::cached;
use colored::Colorize;
use comlexr::cmd;
use indicatif::{ProgressBar, ProgressStyle};
use log::{debug, trace};
use miette::{bail, IntoDiagnostic, Result};
@ -46,8 +46,8 @@ fn get_metadata_cache(opts: &GetMetadataOpts) -> Result<ImageMetadata> {
],
"inspect",
format!("docker://{image_str}"),
stderr = Stdio::inherit(),
);
command.stderr(Stdio::inherit());
trace!("{command:?}");
let output = command.output().into_diagnostic()?;