From c832bcd1aaca3b29ee45accf1673610aaffaf888 Mon Sep 17 00:00:00 2001 From: Gerald Pinder Date: Mon, 22 Jan 2024 17:48:14 -0500 Subject: [PATCH] fix: Rebase path not being generated properly (#8) * fix: Rebase path not being generated properly * consolidate logic into generate_full_image_name * Fix nightly build --- src/commands/build.rs | 48 +++++++++++++++++++------------------------ src/commands/local.rs | 23 +++++++-------------- src/ops.rs | 4 ++-- 3 files changed, 30 insertions(+), 45 deletions(-) diff --git a/src/commands/build.rs b/src/commands/build.rs index ca3a743..3aeef38 100644 --- a/src/commands/build.rs +++ b/src/commands/build.rs @@ -224,17 +224,12 @@ impl BuildCommand { // Get values for image let tags = recipe.generate_tags(); let image_name = self.generate_full_image_name(&recipe)?; - let first_image_name = match &self.archive { - Some(archive_dir) => format!( - "oci-archive:{}", - archive_dir - .join(format!("{image_name}{ARCHIVE_SUFFIX}")) - .display() - ), - None => tags - .first() + let first_image_name = if self.archive.is_some() { + image_name.to_string() + } else { + tags.first() .map(|t| format!("{image_name}:{t}")) - .unwrap_or(image_name.to_string()), + .unwrap_or(image_name.to_string()) }; debug!("Full tag is {first_image_name}"); @@ -434,8 +429,12 @@ impl BuildCommand { trace!("BuildCommand::generate_full_image_name({recipe:#?})"); info!("Generating full image name"); - let image_name = if self.archive.is_some() { - recipe.name.to_string() + let image_name = if let Some(archive_dir) = &self.archive { + format!( + "oci-archive:{}/{}.{ARCHIVE_SUFFIX}", + archive_dir.to_string_lossy().trim_end_matches('/'), + recipe.name.to_lowercase(), + ) } else { match ( env::var("CI_REGISTRY").ok(), @@ -449,9 +448,9 @@ impl BuildCommand { trace!("registry={registry}, registry_path={registry_path}"); format!( "{}/{}/{}", - registry.trim().trim_matches('/'), - registry_path.trim().trim_matches('/'), - &recipe.name + registry.trim().trim_matches('/').to_lowercase(), + registry_path.trim().trim_matches('/').to_lowercase(), + recipe.name.trim().to_lowercase() ) } ( @@ -466,7 +465,7 @@ impl BuildCommand { warn!("Generating Gitlab Registry image"); format!( "{ci_registry}/{ci_project_namespace}/{ci_project_name}/{}", - &recipe.name + recipe.name.trim().to_lowercase() ) } (None, None, None, Some(github_repository_owner), None, None) => { @@ -479,7 +478,7 @@ impl BuildCommand { if self.push { bail!("Need '--registry' and '--registry-path' in order to push image"); } - recipe.name.clone() + recipe.name.trim().to_lowercase() } } }; @@ -495,17 +494,12 @@ impl BuildCommand { fn run_build(&self, image_name: &str, tags: &[String]) -> Result<()> { trace!("BuildCommand::run_build({image_name}, {tags:#?})"); - let full_image = match &self.archive { - Some(archive_dir) => format!( - "oci-archive:{}", - archive_dir - .join(format!("{image_name}{ARCHIVE_SUFFIX}")) - .display() - ), - None => tags - .first() + let full_image = if self.archive.is_some() { + image_name.to_string() + } else { + tags.first() .map(|t| format!("{image_name}:{t}")) - .unwrap_or(image_name.to_string()), + .unwrap_or(image_name.to_string()) }; info!("Building image {full_image}"); diff --git a/src/commands/local.rs b/src/commands/local.rs index 7083cc0..a9d3a6d 100644 --- a/src/commands/local.rs +++ b/src/commands/local.rs @@ -55,19 +55,15 @@ impl BlueBuildCommand for UpgradeCommand { build.try_run()?; - info!("Upgrading from locally built image {image_name}"); - - let image_name = format!("ostree-unverified-image:{image_name}"); - let status = if self.common.reboot { - debug!("Upgrading image {image_name} and rebooting"); + info!("Upgrading image {image_name} and rebooting"); Command::new("rpm-ostree") .arg("upgrade") .arg("--reboot") .status()? } else { - debug!("Upgrading image {image_name}"); + info!("Upgrading image {image_name}"); Command::new("rpm-ostree").arg("upgrade").status()? }; @@ -106,24 +102,20 @@ impl BlueBuildCommand for RebaseCommand { build.try_run()?; - info!("Rebasing onto locally built image {image_name}"); - - let image_name = format!("ostree-unverified-image:{image_name}"); - let status = if self.common.reboot { - debug!("Rebasing image {image_name} and rebooting"); + info!("Rebasing image {image_name} and rebooting"); Command::new("rpm-ostree") .arg("rebase") .arg("--reboot") - .arg(&image_name) + .arg(format!("ostree-unverified-image:{image_name}")) .status()? } else { - debug!("Rebasing image {image_name}"); + info!("Rebasing image {image_name}"); Command::new("rpm-ostree") .arg("rebase") - .arg(&image_name) + .arg(format!("ostree-unverified-image:{image_name}")) .status()? }; @@ -156,8 +148,7 @@ fn clean_local_build_dir(image_name: &str, rebase: bool) -> Result<()> { trace!("clean_local_build_dir()"); let local_build_path = Path::new(LOCAL_BUILD); - let image_file_name = format!("{image_name}.tar.gz"); - let image_file_path = local_build_path.join(image_file_name); + let image_file_path = local_build_path.join(image_name.trim_start_matches("oci-archive:")); if !image_file_path.exists() && !rebase { bail!( diff --git a/src/ops.rs b/src/ops.rs index e0716ef..dc296b0 100644 --- a/src/ops.rs +++ b/src/ops.rs @@ -1,9 +1,9 @@ use anyhow::{anyhow, Result}; use log::{debug, trace}; -use std::process::Command; +use std::{path::Path, process::Command}; pub const LOCAL_BUILD: &str = "/etc/blue-build"; -pub const ARCHIVE_SUFFIX: &str = ".tar.gz"; +pub const ARCHIVE_SUFFIX: &str = "tar.gz"; pub fn check_command_exists(command: &str) -> Result<()> { trace!("check_command_exists({command})");