apt-ostree/demo-oci-build.rs
robojerk ceaa66fb07 Major milestone: Complete apt-ostree bootc compatibility and OCI integration
-  Real package installation (replaced mock installation)
-  Real OSTree commit creation from installed packages
-  OCI image creation from both commits and rootfs
-  Full bootc compatibility with proper labels
-  Comprehensive test suite (test-bootc-apt-ostree.sh)
-  Container tool validation (skopeo, podman)
-  Updated compatibility reports for Ubuntu Questing
-  Fixed OCI schema version and field naming issues
-  Temporary directory lifecycle fixes
-  Serde rename attributes for OCI JSON compliance

Ready for Aurora-style workflow deployment!
2025-07-20 21:06:44 +00:00

83 lines
No EOL
3.5 KiB
Rust

use apt_ostree::oci::{OciImageBuilder, OciBuildOptions};
use std::collections::HashMap;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("=== apt-ostree OCI Image Building Demo ===");
println!();
// Create OCI build options
let mut options = OciBuildOptions::default();
options.format = "oci".to_string();
options.max_layers = 64;
options.user = Some("root".to_string());
options.working_dir = Some("/".to_string());
options.env = vec!["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin".to_string()];
options.exposed_ports = vec!["80".to_string(), "443".to_string()];
options.volumes = vec!["/var/log".to_string(), "/var/cache".to_string()];
options.platform = Some("linux/amd64".to_string());
// Add some labels
options.labels.insert("org.aptostree.demo".to_string(), "true".to_string());
options.labels.insert("org.opencontainers.image.title".to_string(), "apt-ostree-demo".to_string());
options.labels.insert("org.opencontainers.image.description".to_string(), "Demo image built with apt-ostree".to_string());
println!("✅ Created OCI build options:");
println!(" Format: {}", options.format);
println!(" Max layers: {}", options.max_layers);
println!(" User: {:?}", options.user);
println!(" Platform: {:?}", options.platform);
println!(" Labels: {:?}", options.labels);
println!();
// Create OCI image builder
println!("Creating OCI image builder...");
let oci_builder = OciImageBuilder::new(options).await?;
println!("✅ OCI image builder created successfully");
println!();
// Test source (this would normally be an OSTree commit)
let test_source = "test/oci/demo";
let output_name = "/tmp/demo-image.oci";
println!("Building OCI image:");
println!(" Source: {}", test_source);
println!(" Output: {}", output_name);
println!();
// Note: This would fail in a real environment because we don't have an actual OSTree commit
// But it demonstrates the API and structure
match oci_builder.build_image_from_commit(test_source, output_name).await {
Ok(image_path) => {
println!("✅ Successfully built OCI image: {}", image_path);
println!();
println!("Image details:");
println!(" - OCI specification v1.0 compliant");
println!(" - Content-addressed layers with SHA256 digests");
println!(" - Gzip compression for filesystem layers");
println!(" - Proper image manifest and configuration");
println!(" - Registry-ready format");
}
Err(e) => {
println!("⚠️ Expected error (no real OSTree commit): {}", e);
println!();
println!("This is expected because we don't have a real OSTree commit to work with.");
println!("In a real environment with an OSTree repository, this would work!");
}
}
println!();
println!("=== Demo Summary ===");
println!("✅ OCI build options configured");
println!("✅ OCI image builder created");
println!("✅ API structure validated");
println!("⚠️ Real build requires OSTree repository");
println!();
println!("To build a real image:");
println!("1. Initialize OSTree repository");
println!("2. Create OSTree commit");
println!("3. Use apt-ostree oci build command");
println!("4. Validate with skopeo or docker");
Ok(())
}