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
This commit is contained in:
Gerald Pinder 2024-01-22 17:48:14 -05:00 committed by GitHub
parent dbbd087b5b
commit c832bcd1aa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 30 additions and 45 deletions

View file

@ -224,17 +224,12 @@ impl BuildCommand {
// Get values for image // Get values for image
let tags = recipe.generate_tags(); let tags = recipe.generate_tags();
let image_name = self.generate_full_image_name(&recipe)?; let image_name = self.generate_full_image_name(&recipe)?;
let first_image_name = match &self.archive { let first_image_name = if self.archive.is_some() {
Some(archive_dir) => format!( image_name.to_string()
"oci-archive:{}", } else {
archive_dir tags.first()
.join(format!("{image_name}{ARCHIVE_SUFFIX}"))
.display()
),
None => tags
.first()
.map(|t| format!("{image_name}:{t}")) .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}"); debug!("Full tag is {first_image_name}");
@ -434,8 +429,12 @@ impl BuildCommand {
trace!("BuildCommand::generate_full_image_name({recipe:#?})"); trace!("BuildCommand::generate_full_image_name({recipe:#?})");
info!("Generating full image name"); info!("Generating full image name");
let image_name = if self.archive.is_some() { let image_name = if let Some(archive_dir) = &self.archive {
recipe.name.to_string() format!(
"oci-archive:{}/{}.{ARCHIVE_SUFFIX}",
archive_dir.to_string_lossy().trim_end_matches('/'),
recipe.name.to_lowercase(),
)
} else { } else {
match ( match (
env::var("CI_REGISTRY").ok(), env::var("CI_REGISTRY").ok(),
@ -449,9 +448,9 @@ impl BuildCommand {
trace!("registry={registry}, registry_path={registry_path}"); trace!("registry={registry}, registry_path={registry_path}");
format!( format!(
"{}/{}/{}", "{}/{}/{}",
registry.trim().trim_matches('/'), registry.trim().trim_matches('/').to_lowercase(),
registry_path.trim().trim_matches('/'), registry_path.trim().trim_matches('/').to_lowercase(),
&recipe.name recipe.name.trim().to_lowercase()
) )
} }
( (
@ -466,7 +465,7 @@ impl BuildCommand {
warn!("Generating Gitlab Registry image"); warn!("Generating Gitlab Registry image");
format!( format!(
"{ci_registry}/{ci_project_namespace}/{ci_project_name}/{}", "{ci_registry}/{ci_project_namespace}/{ci_project_name}/{}",
&recipe.name recipe.name.trim().to_lowercase()
) )
} }
(None, None, None, Some(github_repository_owner), None, None) => { (None, None, None, Some(github_repository_owner), None, None) => {
@ -479,7 +478,7 @@ impl BuildCommand {
if self.push { if self.push {
bail!("Need '--registry' and '--registry-path' in order to push image"); 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<()> { fn run_build(&self, image_name: &str, tags: &[String]) -> Result<()> {
trace!("BuildCommand::run_build({image_name}, {tags:#?})"); trace!("BuildCommand::run_build({image_name}, {tags:#?})");
let full_image = match &self.archive { let full_image = if self.archive.is_some() {
Some(archive_dir) => format!( image_name.to_string()
"oci-archive:{}", } else {
archive_dir tags.first()
.join(format!("{image_name}{ARCHIVE_SUFFIX}"))
.display()
),
None => tags
.first()
.map(|t| format!("{image_name}:{t}")) .map(|t| format!("{image_name}:{t}"))
.unwrap_or(image_name.to_string()), .unwrap_or(image_name.to_string())
}; };
info!("Building image {full_image}"); info!("Building image {full_image}");

View file

@ -55,19 +55,15 @@ impl BlueBuildCommand for UpgradeCommand {
build.try_run()?; 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 { let status = if self.common.reboot {
debug!("Upgrading image {image_name} and rebooting"); info!("Upgrading image {image_name} and rebooting");
Command::new("rpm-ostree") Command::new("rpm-ostree")
.arg("upgrade") .arg("upgrade")
.arg("--reboot") .arg("--reboot")
.status()? .status()?
} else { } else {
debug!("Upgrading image {image_name}"); info!("Upgrading image {image_name}");
Command::new("rpm-ostree").arg("upgrade").status()? Command::new("rpm-ostree").arg("upgrade").status()?
}; };
@ -106,24 +102,20 @@ impl BlueBuildCommand for RebaseCommand {
build.try_run()?; 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 { let status = if self.common.reboot {
debug!("Rebasing image {image_name} and rebooting"); info!("Rebasing image {image_name} and rebooting");
Command::new("rpm-ostree") Command::new("rpm-ostree")
.arg("rebase") .arg("rebase")
.arg("--reboot") .arg("--reboot")
.arg(&image_name) .arg(format!("ostree-unverified-image:{image_name}"))
.status()? .status()?
} else { } else {
debug!("Rebasing image {image_name}"); info!("Rebasing image {image_name}");
Command::new("rpm-ostree") Command::new("rpm-ostree")
.arg("rebase") .arg("rebase")
.arg(&image_name) .arg(format!("ostree-unverified-image:{image_name}"))
.status()? .status()?
}; };
@ -156,8 +148,7 @@ fn clean_local_build_dir(image_name: &str, rebase: bool) -> Result<()> {
trace!("clean_local_build_dir()"); trace!("clean_local_build_dir()");
let local_build_path = Path::new(LOCAL_BUILD); 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_name.trim_start_matches("oci-archive:"));
let image_file_path = local_build_path.join(image_file_name);
if !image_file_path.exists() && !rebase { if !image_file_path.exists() && !rebase {
bail!( bail!(

View file

@ -1,9 +1,9 @@
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use log::{debug, trace}; use log::{debug, trace};
use std::process::Command; use std::{path::Path, process::Command};
pub const LOCAL_BUILD: &str = "/etc/blue-build"; 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<()> { pub fn check_command_exists(command: &str) -> Result<()> {
trace!("check_command_exists({command})"); trace!("check_command_exists({command})");