feat: Add platform arg to force building a specific architecture
This commit is contained in:
parent
20d1950530
commit
75eae89e4a
22 changed files with 408 additions and 71 deletions
|
|
@ -9,6 +9,7 @@ use blue_build_process_management::{
|
|||
BuildTagPushOpts, CheckKeyPairOpts, CompressionType, GenerateImageNameOpts,
|
||||
GenerateTagsOpts, SignVerifyOpts,
|
||||
},
|
||||
types::Platform,
|
||||
BuildDriver, CiDriver, Driver, DriverArgs, SigningDriver,
|
||||
},
|
||||
logging::{color_str, gen_random_ansi_color},
|
||||
|
|
@ -58,6 +59,16 @@ pub struct BuildCommand {
|
|||
#[builder(default)]
|
||||
push: bool,
|
||||
|
||||
/// Build for a specific platform.
|
||||
///
|
||||
/// NOTE: Building for a different architecture
|
||||
/// than your hardware will require installing
|
||||
/// qemu. Build times will be much greater when
|
||||
/// building for a non-native architecture.
|
||||
#[arg(long, default_value = "native")]
|
||||
#[builder(default)]
|
||||
platform: Platform,
|
||||
|
||||
/// The compression format the images
|
||||
/// will be pushed in.
|
||||
#[arg(short, long, default_value_t = CompressionType::Gzip)]
|
||||
|
|
@ -260,7 +271,8 @@ impl BuildCommand {
|
|||
let tags = Driver::generate_tags(
|
||||
&GenerateTagsOpts::builder()
|
||||
.oci_ref(&recipe.base_image_ref()?)
|
||||
.maybe_alt_tags(recipe.alt_tags.as_ref().map(CowCollecter::to_cow_vec))
|
||||
.maybe_alt_tags(recipe.alt_tags.as_ref().map(CowCollecter::collect_cow_vec))
|
||||
.platform(self.platform)
|
||||
.build(),
|
||||
)?;
|
||||
let image_name = self.image_name(&recipe)?;
|
||||
|
|
@ -268,6 +280,7 @@ impl BuildCommand {
|
|||
let opts = if let Some(archive_dir) = self.archive.as_ref() {
|
||||
BuildTagPushOpts::builder()
|
||||
.containerfile(containerfile)
|
||||
.platform(self.platform)
|
||||
.archive_path(format!(
|
||||
"{}/{}.{ARCHIVE_SUFFIX}",
|
||||
archive_dir.to_string_lossy().trim_end_matches('/'),
|
||||
|
|
@ -279,7 +292,8 @@ impl BuildCommand {
|
|||
BuildTagPushOpts::builder()
|
||||
.image(&image_name)
|
||||
.containerfile(containerfile)
|
||||
.tags(tags.to_cow_vec())
|
||||
.platform(self.platform)
|
||||
.tags(tags.collect_cow_vec())
|
||||
.push(self.push)
|
||||
.retry_push(self.retry_push)
|
||||
.retry_count(self.retry_count)
|
||||
|
|
@ -297,6 +311,7 @@ impl BuildCommand {
|
|||
.retry_push(self.retry_push)
|
||||
.retry_count(self.retry_count)
|
||||
.maybe_tag(tags.first())
|
||||
.platform(self.platform)
|
||||
.build(),
|
||||
)?;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use std::{
|
|||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use blue_build_process_management::drivers::{CiDriver, Driver, DriverArgs};
|
||||
use blue_build_process_management::drivers::{types::Platform, CiDriver, Driver, DriverArgs};
|
||||
use blue_build_recipe::Recipe;
|
||||
use blue_build_template::{ContainerFileTemplate, Template};
|
||||
use blue_build_utils::{
|
||||
|
|
@ -63,6 +63,12 @@ pub struct GenerateCommand {
|
|||
#[arg(short = 't', long)]
|
||||
syntax_theme: Option<DefaultThemes>,
|
||||
|
||||
/// Inspect the image for a specific platform
|
||||
/// when retrieving the version.
|
||||
#[arg(long, default_value = "native")]
|
||||
#[builder(default)]
|
||||
platform: Platform,
|
||||
|
||||
#[clap(flatten)]
|
||||
#[builder(default)]
|
||||
drivers: DriverArgs,
|
||||
|
|
@ -115,7 +121,12 @@ impl GenerateCommand {
|
|||
info!("Templating for recipe at {}", recipe_path.display());
|
||||
|
||||
let template = ContainerFileTemplate::builder()
|
||||
.os_version(Driver::get_os_version(&recipe.base_image_ref()?)?)
|
||||
.os_version(
|
||||
Driver::get_os_version()
|
||||
.oci_ref(&recipe.base_image_ref()?)
|
||||
.platform(self.platform)
|
||||
.call()?,
|
||||
)
|
||||
.build_id(Driver::get_build_id())
|
||||
.recipe(&recipe)
|
||||
.recipe_path(recipe_path.as_path())
|
||||
|
|
|
|||
|
|
@ -203,7 +203,10 @@ impl GenerateIsoCommand {
|
|||
format!("IMAGE_NAME={image_name}",),
|
||||
format!("IMAGE_REPO={image_repo}"),
|
||||
format!("IMAGE_TAG={}", image.tag().unwrap_or("latest")),
|
||||
format!("VERSION={}", Driver::get_os_version(&image)?),
|
||||
format!(
|
||||
"VERSION={}",
|
||||
Driver::get_os_version().oci_ref(&image).call()?
|
||||
),
|
||||
]);
|
||||
}
|
||||
GenIsoSubcommand::Recipe { recipe } => {
|
||||
|
|
@ -216,7 +219,9 @@ impl GenerateIsoCommand {
|
|||
),
|
||||
format!(
|
||||
"VERSION={}",
|
||||
Driver::get_os_version(&recipe.base_image_ref()?)?,
|
||||
Driver::get_os_version()
|
||||
.oci_ref(&recipe.base_image_ref()?)
|
||||
.call()?,
|
||||
),
|
||||
]);
|
||||
vols.extend(run_volumes![
|
||||
|
|
@ -230,7 +235,7 @@ impl GenerateIsoCommand {
|
|||
.image("ghcr.io/jasonn3/build-container-installer")
|
||||
.privileged(true)
|
||||
.remove(true)
|
||||
.args(args.to_cow_vec())
|
||||
.args(args.collect_cow_vec())
|
||||
.volumes(vols)
|
||||
.build();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue