optimized_upload_demo/
optimized_upload_demo.rs

1// Example demonstrating the optimized upload integration
2
3use docker_image_pusher::cli::operation_mode::OperationMode;
4use docker_image_pusher::error::Result;
5use docker_image_pusher::image::ImageManager;
6use docker_image_pusher::registry::PipelineConfig;
7use docker_image_pusher::registry::RegistryClientBuilder;
8
9#[tokio::main]
10async fn main() -> Result<()> {
11    println!("Docker Image Pusher - Optimized Upload Demo");
12
13    // Create image manager with optimizations enabled (default)
14    let mut manager = ImageManager::new(None, true)?;
15
16    // Configure pipeline for demonstration
17    let config = PipelineConfig {
18        max_concurrent: 8,
19        buffer_size: 1024,
20        small_blob_threshold: 10 * 1024 * 1024,   // 10MB
21        medium_blob_threshold: 100 * 1024 * 1024, // 100MB
22        large_blob_threshold: 500 * 1024 * 1024,  // 500MB
23        timeout_seconds: 7200,
24        retry_attempts: 3,
25        memory_limit_mb: 512,
26        enable_compression: true,
27        enable_streaming: true,
28    };
29    manager.configure_pipeline(config);
30
31    // Verify configuration
32    let (optimized, pipeline_config) = manager.get_config();
33    println!("Optimized mode: {}", optimized);
34    println!("Pipeline config: {:?}", pipeline_config);
35
36    // Example registry client (would need real registry URL)
37    let client = RegistryClientBuilder::new("https://registry.example.com".to_string())
38        .with_verbose(true)
39        .build()?;
40
41    // Test connectivity (this would fail with example URL)
42    println!("Testing registry connectivity...");
43    match client.test_connectivity().await {
44        Ok(_) => println!("✓ Registry connectivity successful"),
45        Err(e) => println!(
46            "✗ Registry connectivity failed: {} (expected with example URL)",
47            e
48        ),
49    }
50
51    // Example operation mode for pushing from tar
52    let mode = OperationMode::PushFromTar {
53        tar_file: "example-image.tar".to_string(),
54        repository: "myapp".to_string(),
55        reference: "latest".to_string(),
56    };
57
58    println!("Operation mode: {}", mode.description());
59
60    // In a real scenario, you would call:
61    // manager.execute_operation(&mode, Some(&client), None).await?;
62
63    println!("Demo completed successfully!");
64    println!("\nKey benefits of optimized mode:");
65    println!("• Priority-based upload scheduling (small blobs first)");
66    println!("• Streaming TAR processing with parallel uploads");
67    println!("• Memory-efficient processing of large files");
68    println!("• Configurable pipeline parameters");
69
70    Ok(())
71}