1
0
Fork 0
mirror of https://github.com/imjasonh/krust synced 2026-07-08 06:45:32 +00:00

Merge pull request #52 from imjasonh/conc

build concurrently
This commit is contained in:
Jason Hall 2025-10-15 16:21:57 -04:00 committed by GitHub
commit d9bef924aa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -91,16 +91,23 @@ async fn main() -> Result<()> {
}
};
// Build for each platform
let mut manifest_descriptors = Vec::new();
// Build for each platform concurrently
let mut tasks = Vec::new();
for platform_str in &platforms {
for platform_str in platforms.clone() {
let project_path = project_path.clone();
let base_image = base_image.clone();
let target_repo = target_repo.clone();
let cargo_args = cargo_args.clone();
let no_push_flag = no_push;
let task = tokio::spawn(async move {
info!("Building for platform: {}", platform_str);
// Build the Rust binary for this platform
let target = get_rust_target_triple(platform_str)?;
let target = get_rust_target_triple(&platform_str)?;
let builder =
RustBuilder::new(&project_path, &target).with_cargo_args(cargo_args.clone());
RustBuilder::new(&project_path, &target).with_cargo_args(cargo_args);
let build_result = builder.build()?;
@ -111,6 +118,9 @@ async fn main() -> Result<()> {
platform_str.clone(),
);
// Create a registry client for this task
let mut registry_client = RegistryClient::new()?;
// Always use layered approach - registry layer will handle cross-registry blob copying
let base_auth = resolve_auth(&base_image)?;
let (config_data, layer_data, manifest) = image_builder
@ -118,7 +128,7 @@ async fn main() -> Result<()> {
.await?;
// Push platform-specific image if not --no-push
if !no_push {
let manifest_descriptor = if !no_push_flag {
info!("Pushing image for platform: {}", platform_str);
// Get auth for the target registry
@ -153,7 +163,10 @@ async fn main() -> Result<()> {
let (os, arch) = if parts.len() >= 2 {
(parts[0].to_string(), parts[1].to_string())
} else {
return Err(anyhow::anyhow!("Invalid platform format: {}", platform_str));
return Err(anyhow::anyhow!(
"Invalid platform format: {}",
platform_str
));
};
// Extract just the digest from the full reference
@ -161,12 +174,12 @@ async fn main() -> Result<()> {
info!("Pushed platform image to: {}", digest_ref);
// Add to manifest list
// Return manifest descriptor
info!(
"Adding manifest to list - platform: {}/{}, digest: {}, size: {}",
os, arch, digest, manifest_size
);
manifest_descriptors.push(ManifestDescriptor {
Some(ManifestDescriptor {
media_type: "application/vnd.oci.image.manifest.v1+json".to_string(),
size: manifest_size as i64,
digest,
@ -175,7 +188,23 @@ async fn main() -> Result<()> {
os,
variant: None,
},
})
} else {
None
};
Ok::<_, anyhow::Error>(manifest_descriptor)
});
tasks.push(task);
}
// Wait for all builds to complete
let mut manifest_descriptors = Vec::new();
for task in tasks {
let result = task.await.context("Build task panicked")??;
if let Some(descriptor) = result {
manifest_descriptors.push(descriptor);
}
}