Skip to content

Commit e3784e0

Browse files
authored
feat: add mirror handling and OCI mirror type (#553)
This is the start of the "mirror" implemnetation that would - be able to handle multiple mirrors of a single channel - reroute a channel to an "internal" mirror (for on-prem deployments) - handle OCI channels to pull data from
1 parent a7ab984 commit e3784e0

File tree

10 files changed

+713
-22
lines changed

10 files changed

+713
-22
lines changed

Cargo.toml

+7-5
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ chrono = { version = "0.4.35", default-features = false, features = [
4848
"serde",
4949
"alloc",
5050
] }
51-
clap = { version = "4.5.1", features = ["derive"] }
51+
clap = { version = "4.5.2", features = ["derive"] }
5252
cmake = "0.1.50"
5353
console = { version = "0.15.8", features = ["windows-console-colors"] }
5454
criterion = "0.5"
@@ -67,6 +67,7 @@ getrandom = { version = "0.2.12", default-features = false }
6767
glob = "0.3.1"
6868
hex = "0.4.3"
6969
hex-literal = "0.4.1"
70+
http = "0.2"
7071
humansize = "2.1.3"
7172
humantime = "2.1.0"
7273
indexmap = "2.2.5"
@@ -78,7 +79,7 @@ keyring = "2.3.2"
7879
lazy-regex = "3.1.0"
7980
lazy_static = "1.4.0"
8081
libc = { version = "0.2" }
81-
libloading = "0.8.2"
82+
libloading = "0.8.3"
8283
libz-sys = { version = "1.1.15", default-features = false }
8384
md-5 = "0.10.6"
8485
memchr = "2.7.1"
@@ -98,10 +99,11 @@ quote = "1.0.35"
9899
rand = "0.8.5"
99100
reflink-copy = "0.1.15"
100101
regex = "1.10.3"
101-
reqwest = { version = "0.11.24", default-features = false }
102+
reqwest = { version = "0.11.25", default-features = false }
102103
reqwest-middleware = "0.2.4"
104+
reqwest-retry = "0.4.0"
103105
resolvo = { version = "0.4.0" }
104-
retry-policies = { version = "0.2.1", default-features = false }
106+
retry-policies = { version = "0.3.0", default-features = false }
105107
rstest = { version = "0.18.2" }
106108
rstest_reuse = "0.6.0"
107109
serde = { version = "1.0.197" }
@@ -122,7 +124,7 @@ smallvec = { version = "1.13.1", features = [
122124
strum = { version = "0.26.1", features = ["derive"] }
123125
superslice = "1.0.0"
124126
syn = "2.0.52"
125-
sysinfo = "0.30.6"
127+
sysinfo = "0.30.7"
126128
tar = "0.4.40"
127129
task-local-extensions = "0.1.4"
128130
tempdir = "0.3.7"

crates/rattler/src/package_cache.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use chrono::Utc;
55
use fxhash::FxHashMap;
66
use itertools::Itertools;
77
use rattler_conda_types::{package::ArchiveIdentifier, PackageRecord};
8+
use rattler_digest::Sha256Hash;
89
use rattler_networking::retry_policies::{DoNotRetryPolicy, RetryDecision, RetryPolicy};
910
use rattler_package_streaming::ExtractError;
1011
use reqwest::StatusCode;
@@ -38,6 +39,14 @@ pub struct CacheKey {
3839
name: String,
3940
version: String,
4041
build_string: String,
42+
sha256: Option<Sha256Hash>,
43+
}
44+
45+
impl CacheKey {
46+
/// Return the sha256 hash of the package if it is known.
47+
pub fn sha256(&self) -> Option<Sha256Hash> {
48+
self.sha256
49+
}
4150
}
4251

4352
impl From<ArchiveIdentifier> for CacheKey {
@@ -46,6 +55,7 @@ impl From<ArchiveIdentifier> for CacheKey {
4655
name: pkg.name,
4756
version: pkg.version,
4857
build_string: pkg.build_string,
58+
sha256: None,
4959
}
5060
}
5161
}
@@ -56,6 +66,7 @@ impl From<&PackageRecord> for CacheKey {
5666
name: record.name.as_normalized().to_string(),
5767
version: record.version.to_string(),
5868
build_string: record.build.clone(),
69+
sha256: record.sha256,
5970
}
6071
}
6172
}
@@ -200,7 +211,10 @@ impl PackageCache {
200211
client: reqwest_middleware::ClientWithMiddleware,
201212
retry_policy: impl RetryPolicy + Send + 'static,
202213
) -> Result<PathBuf, PackageCacheError> {
203-
self.get_or_fetch(pkg, move |destination| async move {
214+
let request_start = Utc::now();
215+
let cache_key = pkg.into();
216+
let sha256 = cache_key.sha256();
217+
self.get_or_fetch(cache_key, move |destination| async move {
204218
let mut current_try = 0;
205219
loop {
206220
current_try += 1;
@@ -209,6 +223,7 @@ impl PackageCache {
209223
client.clone(),
210224
url.clone(),
211225
&destination,
226+
sha256,
212227
)
213228
.await;
214229

@@ -230,7 +245,7 @@ impl PackageCache {
230245
}
231246

232247
// Determine whether or not to retry based on the retry policy
233-
let execute_after = match retry_policy.should_retry(current_try) {
248+
let execute_after = match retry_policy.should_retry(request_start, current_try) {
234249
RetryDecision::Retry { execute_after } => execute_after,
235250
RetryDecision::DoNotRetry => return Err(err),
236251
};

crates/rattler_networking/Cargo.toml

+6
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@ license.workspace = true
1111
readme.workspace = true
1212

1313
[features]
14+
default = ["native-tls"]
1415
native-tls = ['reqwest/native-tls']
1516
rustls-tls = ['reqwest/rustls-tls']
1617

1718
[dependencies]
1819
anyhow = { workspace = true }
1920
async-trait = { workspace = true }
2021
base64 = { workspace = true }
22+
chrono = { workspace = true }
2123
dirs = { workspace = true }
2224
fslock = { workspace = true }
25+
http = { workspace = true }
2326
itertools = { workspace = true }
2427
keyring = { workspace = true }
2528
lazy_static = { workspace = true }
@@ -44,3 +47,6 @@ anyhow = { workspace = true }
4447
insta = { workspace = true, features = ["json"] }
4548
tempfile = { workspace = true }
4649
tokio = { workspace = true, features = ["macros"] }
50+
axum = { workspace = true }
51+
reqwest-retry = { workspace = true }
52+
sha2 = { workspace = true }

crates/rattler_networking/src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
//! Networking utilities for Rattler, specifically authenticating requests
44
pub use authentication_middleware::AuthenticationMiddleware;
5-
65
pub use authentication_storage::{authentication::Authentication, storage::AuthenticationStorage};
6+
pub use mirror_middleware::MirrorMiddleware;
7+
pub use oci_middleware::OciMiddleware;
78

89
pub mod authentication_middleware;
910
pub mod authentication_storage;
11+
pub mod mirror_middleware;
12+
pub mod oci_middleware;
1013
pub mod retry_policies;
1114

1215
mod redaction;

0 commit comments

Comments
 (0)