Expand description
ImageBuilder - High-level API for building container images
This module provides the ImageBuilder type which orchestrates the full
container image build process, from Dockerfile parsing through buildah
execution to final image creation.
§Example
use zlayer_builder::{ImageBuilder, Runtime};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Build from a Dockerfile
let image = ImageBuilder::new("./my-app").await?
.tag("myapp:latest")
.tag("myapp:v1.0.0")
.build()
.await?;
println!("Built image: {}", image.image_id);
Ok(())
}§Using Runtime Templates
use zlayer_builder::{ImageBuilder, Runtime};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Build using a runtime template (no Dockerfile needed)
let image = ImageBuilder::new("./my-node-app").await?
.runtime(Runtime::Node20)
.tag("myapp:latest")
.build()
.await?;
println!("Built image: {}", image.image_id);
Ok(())
}§Multi-stage Builds with Target
use zlayer_builder::ImageBuilder;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Build only up to a specific stage
let image = ImageBuilder::new("./my-app").await?
.target("builder")
.tag("myapp:builder")
.build()
.await?;
println!("Built intermediate image: {}", image.image_id);
Ok(())
}§With TUI Progress Updates
use zlayer_builder::{ImageBuilder, BuildEvent};
use std::sync::mpsc;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let (tx, rx) = mpsc::channel::<BuildEvent>();
// Start TUI in another thread
std::thread::spawn(move || {
// Process events from rx...
while let Ok(event) = rx.recv() {
println!("Event: {:?}", event);
}
});
let image = ImageBuilder::new("./my-app").await?
.tag("myapp:latest")
.with_events(tx)
.build()
.await?;
Ok(())
}§With Cache Backend (requires cache feature)
ⓘ
use zlayer_builder::ImageBuilder;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let image = ImageBuilder::new("./my-app").await?
.with_cache_dir("/var/cache/zlayer") // Use persistent disk cache
.tag("myapp:latest")
.build()
.await?;
println!("Built image: {}", image.image_id);
Ok(())
}Structs§
- Build
Options - Build options for customizing the image build process
- Built
Image - Built image information returned after a successful build
- Image
Builder - Image builder - orchestrates the full build process
- Registry
Auth - Registry authentication credentials
Enums§
- Build
Output - Output from parsing a
ZImagefile- either a Dockerfile for container builds or a WASM build result for WebAssembly builds.