chore: Use get_env_var

This commit is contained in:
Gerald Pinder 2025-05-16 09:55:28 -04:00
parent 9c24675483
commit 4a0fc3b4a1
7 changed files with 37 additions and 32 deletions

View file

@ -1,5 +1,4 @@
use std::{
env,
ops::Not,
path::Path,
process::{Command, ExitStatus},
@ -8,6 +7,7 @@ use std::{
use blue_build_utils::{
constants::{BLUE_BUILD, DOCKER_HOST, GITHUB_ACTIONS},
credentials::Credentials,
get_env_var,
semver::Version,
string_vec,
};
@ -85,7 +85,7 @@ impl DockerDriver {
trace!("{ls_out}");
if !ls_out.lines().any(|line| line == BLUE_BUILD) {
let remote = env::var(DOCKER_HOST).is_ok();
let remote = get_env_var(DOCKER_HOST).is_ok();
if remote {
let context_list = get_context_list()?;
trace!("{context_list:#?}");
@ -410,10 +410,8 @@ impl BuildDriver for DockerDriver {
}
fn build_tag_push_cmd(opts: &BuildTagPushOpts<'_>, first_image: &str) -> Command {
// let remote = env::var(DOCKER_HOST).is_ok();
let c = cmd!(
"docker",
// if remote => format!("--context={BLUE_BUILD}0"),
"buildx",
format!("--builder={BLUE_BUILD}"),
"build",
@ -426,7 +424,7 @@ fn build_tag_push_cmd(opts: &BuildTagPushOpts<'_>, first_image: &str) -> Command
opts.compression
),
],
ImageRef::Remote(_remote) if env::var(GITHUB_ACTIONS).is_err() => "--load",
ImageRef::Remote(_remote) if get_env_var(GITHUB_ACTIONS).is_err() => "--load",
ImageRef::LocalTar(archive_path) => [
"--output",
format!("type=oci,dest={}", archive_path.display()),

View file

@ -1,8 +1,8 @@
use std::{env, path::Path};
use std::path::Path;
use blue_build_utils::{
constants::{BB_PRIVATE_KEY, COSIGN_PRIV_PATH, COSIGN_PRIVATE_KEY, COSIGN_PUB_PATH},
string,
get_env_var, string,
};
use miette::{Result, bail};
@ -17,8 +17,8 @@ where
Ok(
match (
path.join(COSIGN_PUB_PATH).exists(),
env::var(BB_PRIVATE_KEY).ok(),
env::var(COSIGN_PRIVATE_KEY).ok(),
get_env_var(BB_PRIVATE_KEY).ok(),
get_env_var(COSIGN_PRIVATE_KEY).ok(),
path.join(COSIGN_PRIV_PATH),
) {
(true, Some(private_key), _, _) if !private_key.is_empty() => {

View file

@ -1,9 +1,10 @@
use std::{
borrow::Cow,
env, fs,
fs,
path::{Path, PathBuf},
};
use blue_build_utils::get_env_var;
use bon::Builder;
use miette::{IntoDiagnostic, Result};
use oci_distribution::Reference;
@ -49,7 +50,7 @@ impl PrivateKeyContents<Vec<u8>> for PrivateKey {
impl PrivateKeyContents<String> for PrivateKey {
fn contents(&self) -> Result<Zeroizing<String>> {
Ok(Zeroizing::new(match *self {
Self::Env(ref env) => env::var(env).into_diagnostic()?,
Self::Env(ref env) => get_env_var(env)?,
Self::Path(ref path) => fs::read_to_string(path).into_diagnostic()?,
}))
}

View file

@ -1,12 +1,12 @@
use std::{
borrow::Cow,
collections::HashMap,
env,
path::{Path, PathBuf},
};
use blue_build_utils::{
constants::{GITHUB_ACTIONS, GITLAB_CI, IMAGE_VERSION_LABEL},
get_env_var,
semver::Version,
};
use clap::ValueEnum;
@ -175,7 +175,10 @@ impl DetermineDriver<CiDriverType> for Option<CiDriverType> {
trace!("CiDriverType::determine_driver()");
*self.get_or_insert(
match (env::var(GITLAB_CI).ok(), env::var(GITHUB_ACTIONS).ok()) {
match (
get_env_var(GITLAB_CI).ok(),
get_env_var(GITHUB_ACTIONS).ok(),
) {
(Some(_gitlab_ci), None) => CiDriverType::Gitlab,
(None, Some(_github_actions)) => CiDriverType::Github,
_ => CiDriverType::Local,