refactor: Make use of Reference to ensure typing
This commit is contained in:
parent
f85a761a29
commit
4a7293889d
15 changed files with 230 additions and 205 deletions
|
|
@ -26,6 +26,7 @@ use bon::Builder;
|
|||
use clap::Args;
|
||||
use log::{info, trace, warn};
|
||||
use miette::{bail, IntoDiagnostic, Result};
|
||||
use oci_distribution::Reference;
|
||||
use tempfile::TempDir;
|
||||
|
||||
use crate::commands::generate::GenerateCommand;
|
||||
|
|
@ -299,12 +300,15 @@ impl BuildCommand {
|
|||
.build(),
|
||||
)?;
|
||||
let image_name = self.image_name(&recipe)?;
|
||||
let image: Reference = format!("{image_name}:{}", tags.first().map_or("latest", |tag| tag))
|
||||
.parse()
|
||||
.into_diagnostic()?;
|
||||
|
||||
let build_fn = || -> Result<Vec<String>> {
|
||||
Driver::build_tag_push(&self.archive.as_ref().map_or_else(
|
||||
|| {
|
||||
BuildTagPushOpts::builder()
|
||||
.image(&image_name)
|
||||
.image(&image)
|
||||
.containerfile(containerfile)
|
||||
.platform(self.platform)
|
||||
.tags(tags.collect_cow_vec())
|
||||
|
|
@ -319,11 +323,11 @@ impl BuildCommand {
|
|||
BuildTagPushOpts::builder()
|
||||
.containerfile(containerfile)
|
||||
.platform(self.platform)
|
||||
.archive_path(format!(
|
||||
.archive_path(PathBuf::from(format!(
|
||||
"{}/{}.{ARCHIVE_SUFFIX}",
|
||||
archive_dir.to_string_lossy().trim_end_matches('/'),
|
||||
recipe.name.to_lowercase().replace('/', "_"),
|
||||
))
|
||||
)))
|
||||
.squash(self.squash)
|
||||
.build()
|
||||
},
|
||||
|
|
@ -337,6 +341,10 @@ impl BuildCommand {
|
|||
InspectDriver, RechunkDriver,
|
||||
};
|
||||
|
||||
let base_image: Reference = format!("{}:{}", &recipe.base_image, &recipe.image_version)
|
||||
.parse()
|
||||
.into_diagnostic()?;
|
||||
|
||||
Driver::rechunk(
|
||||
&RechunkOpts::builder()
|
||||
.image(&image_name)
|
||||
|
|
@ -357,8 +365,7 @@ impl BuildCommand {
|
|||
.base_digest(
|
||||
Driver::get_metadata(
|
||||
&GetMetadataOpts::builder()
|
||||
.image(&*recipe.base_image)
|
||||
.tag(&*recipe.image_version)
|
||||
.image(&base_image)
|
||||
.platform(self.platform)
|
||||
.build(),
|
||||
)?
|
||||
|
|
@ -382,10 +389,9 @@ impl BuildCommand {
|
|||
if self.push && !self.no_sign {
|
||||
Driver::sign_and_verify(
|
||||
&SignVerifyOpts::builder()
|
||||
.image(&image_name)
|
||||
.image(&image)
|
||||
.retry_push(self.retry_push)
|
||||
.retry_count(self.retry_count)
|
||||
.maybe_tag(tags.first())
|
||||
.platform(self.platform)
|
||||
.build(),
|
||||
)?;
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ use cached::proc_macro::cached;
|
|||
use clap::{crate_version, Args};
|
||||
use log::{debug, info, trace, warn};
|
||||
use miette::{IntoDiagnostic, Result};
|
||||
use oci_distribution::Reference;
|
||||
|
||||
#[cfg(feature = "validate")]
|
||||
use crate::commands::validate::ValidateCommand;
|
||||
|
|
@ -132,6 +133,10 @@ impl GenerateCommand {
|
|||
|
||||
info!("Templating for recipe at {}", recipe_path.display());
|
||||
|
||||
let base_image: Reference = format!("{}:{}", &recipe.base_image, &recipe.image_version)
|
||||
.parse()
|
||||
.into_diagnostic()?;
|
||||
|
||||
let template = ContainerFileTemplate::builder()
|
||||
.os_version(
|
||||
Driver::get_os_version()
|
||||
|
|
@ -144,12 +149,11 @@ impl GenerateCommand {
|
|||
.recipe_path(recipe_path.as_path())
|
||||
.registry(registry)
|
||||
.repo(Driver::get_repo_url()?)
|
||||
.build_scripts_image(determine_scripts_tag(self.platform)?)
|
||||
.build_scripts_image(determine_scripts_tag(self.platform)?.to_string())
|
||||
.base_digest(
|
||||
Driver::get_metadata(
|
||||
&GetMetadataOpts::builder()
|
||||
.image(&*recipe.base_image)
|
||||
.tag(&*recipe.image_version)
|
||||
.image(&base_image)
|
||||
.platform(self.platform)
|
||||
.build(),
|
||||
)?
|
||||
|
|
@ -178,24 +182,30 @@ impl GenerateCommand {
|
|||
convert = r#"{ platform }"#,
|
||||
sync_writes = true
|
||||
)]
|
||||
fn determine_scripts_tag(platform: Platform) -> Result<String> {
|
||||
let version = format!("v{}", crate_version!());
|
||||
let opts = GetMetadataOpts::builder()
|
||||
.image(BUILD_SCRIPTS_IMAGE_REF)
|
||||
.platform(platform);
|
||||
fn determine_scripts_tag(platform: Platform) -> Result<Reference> {
|
||||
let image: Reference = format!("{BUILD_SCRIPTS_IMAGE_REF}:{}", shadow::COMMIT_HASH)
|
||||
.parse()
|
||||
.into_diagnostic()?;
|
||||
let opts = GetMetadataOpts::builder().platform(platform);
|
||||
|
||||
Driver::get_metadata(&opts.clone().tag(shadow::COMMIT_HASH).build())
|
||||
Driver::get_metadata(&opts.clone().image(&image).build())
|
||||
.inspect_err(|e| trace!("{e:?}"))
|
||||
.map(|_| format!("{BUILD_SCRIPTS_IMAGE_REF}:{}", shadow::COMMIT_HASH))
|
||||
.map(|_| image)
|
||||
.or_else(|_| {
|
||||
Driver::get_metadata(&opts.clone().tag(shadow::BRANCH).build())
|
||||
let image: Reference = format!("{BUILD_SCRIPTS_IMAGE_REF}:{}", shadow::BRANCH)
|
||||
.parse()
|
||||
.into_diagnostic()?;
|
||||
Driver::get_metadata(&opts.clone().image(&image).build())
|
||||
.inspect_err(|e| trace!("{e:?}"))
|
||||
.map(|_| format!("{BUILD_SCRIPTS_IMAGE_REF}:{}", shadow::BRANCH))
|
||||
.map(|_| image)
|
||||
})
|
||||
.or_else(|_| {
|
||||
Driver::get_metadata(&opts.tag(&version).build())
|
||||
let image: Reference = format!("{BUILD_SCRIPTS_IMAGE_REF}:v{}", crate_version!())
|
||||
.parse()
|
||||
.into_diagnostic()?;
|
||||
Driver::get_metadata(&opts.image(&image).build())
|
||||
.inspect_err(|e| trace!("{e:?}"))
|
||||
.map(|_| format!("{BUILD_SCRIPTS_IMAGE_REF}:{version}"))
|
||||
.map(|_| image)
|
||||
})
|
||||
.inspect(|image| debug!("Using build scripts image: {image}"))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue