Skip to content

Commit 8051480

Browse files
src: experimental http client support
It turns out that the information contained in splitstreams to assist with garbage collection (ie: the list of things that we mustn't discard) is exactly the required information for downloading (ie: the list of things that we must acquire). Use this fact to add support for fetching repository content from HTTP servers. We only download the objects that are actually required, so incremental pulls are very fast. This works with just about any HTTP server, so you can do something like python -m http.server -d ~/.var/lib/composefs and download from that. With a fast enough web server on localhost, pulling a complete image into an empty repository takes about as long as pulling an `oci:` directory via skopeo with `cfsctl oci pull`. In practice, this is intended to be used with a webserver which supports static compression and pre-compressed objects stored on the server. In particular, zstd support is enabled in the `reqwest` crate for this reason, and it's working with something like: find repo/objects/ -type f -name '*[0-9a-f]' -exec zstd -19 -v '{}' + static-web-server -p 8888 --compression-static -d repo There's also an included s3-uploader.py in the examples/ directory which will upload a repository to an S3 bucket, with zstd compression. Signed-off-by: Allison Karlitskaya <[email protected]>
1 parent e2e3098 commit 8051480

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ version.workspace = true
1212

1313
[features]
1414
default = ['pre-6.15', 'oci']
15+
http = ['composefs-http']
1516
oci = ['composefs-oci']
1617
rhel9 = ['composefs/rhel9']
1718
'pre-6.15' = ['composefs/pre-6.15']
@@ -22,6 +23,7 @@ clap = { version = "4.0.1", default-features = false, features = ["std", "help",
2223
composefs = { workspace = true }
2324
composefs-boot = { workspace = true }
2425
composefs-oci = { workspace = true, optional = true }
26+
composefs-http = { workspace = true, optional = true }
2527
env_logger = { version = "0.11.0", default-features = false }
2628
hex = { version = "0.4.0", default-features = false }
2729
rustix = { version = "1.0.0", default-features = false, features = ["fs", "process"] }

src/main.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ enum Command {
140140
ImageObjects {
141141
name: String,
142142
},
143+
#[cfg(feature = "http")]
144+
Fetch {
145+
url: String,
146+
name: String,
147+
},
143148
}
144149

145150
fn verity_opt(opt: &Option<String>) -> Result<Option<Sha256HashValue>> {
@@ -345,6 +350,12 @@ async fn main() -> Result<()> {
345350
Command::GC => {
346351
repo.gc()?;
347352
}
353+
#[cfg(feature = "http")]
354+
Command::Fetch { url, name } => {
355+
let (sha256, verity) = composefs_http::download(&url, &name, Arc::new(repo)).await?;
356+
println!("sha256 {}", hex::encode(sha256));
357+
println!("verity {}", verity.to_hex());
358+
}
348359
}
349360
Ok(())
350361
}

0 commit comments

Comments
 (0)