fix: clippy

This commit is contained in:
Gerald Pinder 2023-12-17 22:04:27 -05:00
parent 5b1f99759c
commit f437bdaffa
2 changed files with 7 additions and 8 deletions

View file

@ -30,7 +30,7 @@ fn generate_tags(recipe: &Recipe) -> Vec<String> {
let image_version = recipe.image_version; let image_version = recipe.image_version;
let timestamp = Local::now().format("%Y%m%d").to_string(); let timestamp = Local::now().format("%Y%m%d").to_string();
if let Ok(_) = env::var("CI") { if env::var("CI").is_ok() {
eprintln!("Detected running in Gitlab, pulling information from CI variables..."); eprintln!("Detected running in Gitlab, pulling information from CI variables...");
if let (Ok(mr_iid), Ok(pipeline_source)) = ( if let (Ok(mr_iid), Ok(pipeline_source)) = (
@ -55,9 +55,9 @@ fn generate_tags(recipe: &Recipe) -> Vec<String> {
tags.push(format!("br-{commit_branch}-{image_version}")); tags.push(format!("br-{commit_branch}-{image_version}"));
} else { } else {
eprintln!("Running on the default branch..."); eprintln!("Running on the default branch...");
tags.push(format!("{image_version}")); tags.push(image_version.to_string());
tags.push(format!("{image_version}-{timestamp}")); tags.push(format!("{image_version}-{timestamp}"));
tags.push(format!("{timestamp}")); tags.push(timestamp.to_string());
} }
} }
} else { } else {
@ -130,7 +130,7 @@ fn generate_full_image_name(
eprintln!("Generating full image name"); eprintln!("Generating full image name");
let image_name = recipe.name.as_str(); let image_name = recipe.name.as_str();
let image_name = if let Ok(_) = env::var("CI") { let image_name = if env::var("CI").is_ok() {
eprintln!("Detected running in Gitlab CI..."); eprintln!("Detected running in Gitlab CI...");
if let (Ok(registry), Ok(project_namespace), Ok(project_name)) = ( if let (Ok(registry), Ok(project_namespace), Ok(project_name)) = (
env::var("CI_REGISTRY"), env::var("CI_REGISTRY"),
@ -303,11 +303,10 @@ pub fn build_image(
let tags = generate_tags(&recipe); let tags = generate_tags(&recipe);
let image_name = let image_name = generate_full_image_name(&recipe, registry, registry_path, push)?;
generate_full_image_name(&recipe, registry.clone(), registry_path.clone(), push)?;
if push { if push {
login(registry.clone(), username.clone(), password.clone())?; login(registry, username, password)?;
} }
build(&image_name, &tags, push)?; build(&image_name, &tags, push)?;

View file

@ -29,7 +29,7 @@ use tera::{Context, Tera};
pub const DEFAULT_CONTAINERFILE: &str = include_str!("../templates/Containerfile.tera"); pub const DEFAULT_CONTAINERFILE: &str = include_str!("../templates/Containerfile.tera");
fn setup_tera(recipe: &Path, containerfile: Option<&PathBuf>) -> Result<(Tera, Context)> { fn setup_tera(recipe: &Path, containerfile: Option<&PathBuf>) -> Result<(Tera, Context)> {
let recipe_de = serde_yaml::from_str::<Recipe>(fs::read_to_string(&recipe)?.as_str())?; let recipe_de = serde_yaml::from_str::<Recipe>(fs::read_to_string(recipe)?.as_str())?;
let mut context = Context::from_serialize(recipe_de)?; let mut context = Context::from_serialize(recipe_de)?;
context.insert("recipe", &recipe); context.insert("recipe", &recipe);