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
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}");

View file

@ -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!(

View file

@ -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})");