docker_image_pusher/registry/
mod.rs

1//! Registry client module
2//!
3//! This module provides authentication, client logic, and unified pipeline operations for
4//! interacting with Docker Registry HTTP API v2. It supports login, token management, and
5//! robust error handling for registry operations.
6//!
7//! ## Unified Pipeline Architecture
8//!
9//! The registry module uses a unified pipeline approach that handles both uploads and
10//! downloads with priority-based scheduling, eliminating redundancy and simplifying the codebase.
11
12// Core registry functionality
13pub mod auth;
14pub mod client;
15pub mod tar;
16pub mod tar_utils;
17
18// Unified pipeline operations (consolidates all upload/download functionality)
19pub mod progress;
20pub mod stats;
21pub mod unified_pipeline;
22
23// Core registry exports
24pub use auth::Auth;
25pub use client::{RegistryClient, RegistryClientBuilder};
26pub use tar_utils::TarUtils;
27
28// Unified pipeline exports (primary interface)
29pub use progress::ProgressTracker;
30pub use stats::{LayerUploadStats, ProgressReporter, UploadStats};
31pub use unified_pipeline::{PipelineConfig, PipelineTask, TaskOperation, UnifiedPipeline};
32
33// No legacy exports needed - using unified pipeline only
34
35use crate::error::Result;
36use crate::logging::Logger;
37
38/// Simplified upload configuration (consolidated)
39#[derive(Debug, Clone)]
40pub struct UploadConfig {
41    pub max_concurrent: usize,
42    pub timeout_seconds: u64,
43    pub retry_attempts: usize,
44    pub large_layer_threshold: u64,
45    pub small_blob_threshold: u64,
46    pub enable_streaming: bool,
47}
48
49impl Default for UploadConfig {
50    fn default() -> Self {
51        Self {
52            max_concurrent: 4,
53            timeout_seconds: 7200,
54            retry_attempts: 3,
55            large_layer_threshold: 100 * 1024 * 1024, // 100MB
56            small_blob_threshold: 10 * 1024 * 1024,   // 10MB
57            enable_streaming: true,
58        }
59    }
60}
61
62/// Unified uploader interface (simplified)
63pub struct Uploader {
64    pipeline: UnifiedPipeline,
65}
66
67impl Uploader {
68    /// Create new uploader with unified pipeline
69    pub fn new(pipeline: UnifiedPipeline) -> Self {
70        Self { pipeline }
71    }
72
73    /// Upload layers using unified pipeline
74    pub async fn upload_layers(
75        &self,
76        layers: &[crate::image::parser::LayerInfo],
77        repository: &str,
78        tar_path: &std::path::Path,
79        token: &Option<String>,
80        client: std::sync::Arc<crate::registry::RegistryClient>,
81    ) -> Result<()> {
82        self.pipeline
83            .process_uploads(layers, repository, tar_path, token, client)
84            .await
85    }
86}
87
88/// Registry coordinator (simplified and unified)
89pub struct RegistryCoordinator {
90    pipeline: UnifiedPipeline,
91    config: PipelineConfig,
92}
93
94impl RegistryCoordinator {
95    /// Create coordinator with unified pipeline
96    pub fn new(output: Logger) -> Self {
97        let config = PipelineConfig::default();
98        let pipeline = UnifiedPipeline::new(output).with_config(config.clone());
99
100        Self { pipeline, config }
101    }
102
103    /// Create coordinator with custom configuration
104    pub fn with_config(output: Logger, config: PipelineConfig) -> Self {
105        let pipeline = UnifiedPipeline::new(output).with_config(config.clone());
106
107        Self { pipeline, config }
108    }
109
110    /// Create uploader using unified pipeline
111    pub fn create_uploader(&self) -> Uploader {
112        Uploader::new(self.pipeline.clone())
113    }
114
115    /// Get the current pipeline configuration
116    pub fn get_config(&self) -> &PipelineConfig {
117        &self.config
118    }
119
120    /// Upload layers using unified pipeline
121    pub async fn upload_layers(
122        &self,
123        layers: &[crate::image::parser::LayerInfo],
124        repository: &str,
125        tar_path: &std::path::Path,
126        token: &Option<String>,
127        client: std::sync::Arc<crate::registry::RegistryClient>,
128    ) -> Result<()> {
129        self.pipeline
130            .process_uploads(layers, repository, tar_path, token, client)
131            .await
132    }
133
134    /// Download layers using unified pipeline
135    pub async fn download_layers(
136        &self,
137        layers: &[crate::image::parser::LayerInfo],
138        repository: &str,
139        token: &Option<String>,
140        client: std::sync::Arc<crate::registry::RegistryClient>,
141        cache: &mut crate::image::cache::Cache,
142    ) -> Result<()> {
143        self.pipeline
144            .process_downloads(layers, repository, token, client, cache)
145            .await
146    }
147}