Skip to content

Commit 2ed83a2

Browse files
committed
Add composefs-ostree and some basic CLI tools
Based on ideas from #141 This is an initial version of ostree support. This allows pulling from local and remote ostree repos, which will create a set of regular file content objects, as well as a blob containing all the remaining ostree objects. From the blob we can create an image. When pulling a commit, a base blob (i.e. "the previous version" can be specified. Any objects in that base blob will not be downloaded. If a name is given for the pulled commit, then pre-existing blobs with the same name will automatically be used as a base blob. This is an initial version and there are several things missing: * Pull operations are completely serial * There is no support for ostree summary files * There is no support for ostree delta files * There is no caching of local file availability (other than base blob) * Local ostree repos only support archive mode * There is no GPG validation on ostree pull Signed-off-by: Alexander Larsson <[email protected]>
1 parent cd6470b commit 2ed83a2

File tree

9 files changed

+1567
-1
lines changed

9 files changed

+1567
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ composefs = { version = "0.3.0", path = "crates/composefs", default-features = f
1919
composefs-oci = { version = "0.3.0", path = "crates/composefs-oci", default-features = false }
2020
composefs-boot = { version = "0.3.0", path = "crates/composefs-boot", default-features = false }
2121
composefs-http = { version = "0.3.0", path = "crates/composefs-http", default-features = false }
22+
composefs-ostree = { version = "0.3.0", path = "crates/composefs-ostree", default-features = false }
2223

2324
[profile.dev.package.sha2]
2425
# this is *really* slow otherwise

crates/cfsctl/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ rust-version.workspace = true
1111
version.workspace = true
1212

1313
[features]
14-
default = ['pre-6.15', 'oci']
14+
default = ['pre-6.15', 'oci','ostree']
1515
http = ['composefs-http']
1616
oci = ['composefs-oci']
17+
ostree = ['composefs-ostree']
1718
rhel9 = ['composefs/rhel9']
1819
'pre-6.15' = ['composefs/pre-6.15']
1920

@@ -24,6 +25,7 @@ composefs = { workspace = true }
2425
composefs-boot = { workspace = true }
2526
composefs-oci = { workspace = true, optional = true }
2627
composefs-http = { workspace = true, optional = true }
28+
composefs-ostree = { workspace = true, optional = true }
2729
env_logger = { version = "0.11.0", default-features = false }
2830
hex = { version = "0.4.0", default-features = false }
2931
rustix = { version = "1.0.0", default-features = false, features = ["fs", "process"] }

crates/cfsctl/src/main.rs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,30 @@ enum OciCommand {
8686
},
8787
}
8888

89+
#[cfg(feature = "ostree")]
90+
#[derive(Debug, Subcommand)]
91+
enum OstreeCommand {
92+
PullLocal {
93+
repo_path: PathBuf,
94+
ostree_ref: String,
95+
name: Option<String>,
96+
#[clap(long)]
97+
base_name: Option<String>,
98+
},
99+
Pull {
100+
repo_url: String,
101+
ostree_ref: String,
102+
name: Option<String>,
103+
#[clap(long)]
104+
base_name: Option<String>,
105+
},
106+
CreateImage {
107+
commit_name: String,
108+
#[clap(long)]
109+
image_name: Option<String>,
110+
},
111+
}
112+
89113
#[derive(Debug, Subcommand)]
90114
enum Command {
91115
/// Take a transaction lock on the repository.
@@ -108,6 +132,12 @@ enum Command {
108132
#[clap(subcommand)]
109133
cmd: OciCommand,
110134
},
135+
/// Commands for dealing with OSTree commits
136+
#[cfg(feature = "ostree")]
137+
Ostree {
138+
#[clap(subcommand)]
139+
cmd: OstreeCommand,
140+
},
111141
/// Mounts a composefs, possibly enforcing fsverity of the image
112142
Mount {
113143
/// the name of the image to mount, either a sha256 digest or prefixed with 'ref/'
@@ -302,6 +332,51 @@ async fn main() -> Result<()> {
302332
create_dir_all(state.join("etc/work"))?;
303333
}
304334
},
335+
#[cfg(feature = "ostree")]
336+
Command::Ostree { cmd: ostree_cmd } => match ostree_cmd {
337+
OstreeCommand::PullLocal {
338+
ref repo_path,
339+
ref ostree_ref,
340+
name,
341+
base_name,
342+
} => {
343+
let verity = composefs_ostree::pull_local(
344+
&Arc::new(repo),
345+
repo_path,
346+
ostree_ref,
347+
name.as_deref(),
348+
base_name.as_deref(),
349+
)
350+
.await?;
351+
352+
println!("verity {}", verity.to_hex());
353+
}
354+
OstreeCommand::Pull {
355+
ref repo_url,
356+
ref ostree_ref,
357+
name,
358+
base_name,
359+
} => {
360+
let verity = composefs_ostree::pull(
361+
&Arc::new(repo),
362+
repo_url,
363+
ostree_ref,
364+
name.as_deref(),
365+
base_name.as_deref(),
366+
)
367+
.await?;
368+
369+
println!("verity {}", verity.to_hex());
370+
}
371+
OstreeCommand::CreateImage {
372+
ref commit_name,
373+
ref image_name,
374+
} => {
375+
let mut fs = composefs_ostree::create_filesystem(&repo, commit_name)?;
376+
let image_id = fs.commit_image(&repo, image_name.as_deref())?;
377+
println!("{}", image_id.to_id());
378+
}
379+
},
305380
Command::ComputeId {
306381
ref path,
307382
bootable,

crates/composefs-ostree/Cargo.toml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[package]
2+
name = "composefs-ostree"
3+
description = "ostree support for composefs"
4+
keywords = ["composefs", "ostree"]
5+
6+
edition.workspace = true
7+
license.workspace = true
8+
readme.workspace = true
9+
repository.workspace = true
10+
rust-version.workspace = true
11+
version.workspace = true
12+
13+
[dependencies]
14+
anyhow = { version = "1.0.87", default-features = false }
15+
composefs = { workspace = true }
16+
configparser = { version = "3.1.0", features = [] }
17+
flate2 = { version = "1.1.2", default-features = true }
18+
gvariant = { version = "0.5.0", default-features = true}
19+
hex = { version = "0.4.0", default-features = false, features = ["std"] }
20+
memmap2 = { version = "0.9.5", default-features = true }
21+
rustix = { version = "1.0.0", default-features = false, features = ["fs", "mount", "process", "std"] }
22+
sha2 = { version = "0.10.1", default-features = false }
23+
zerocopy = { version = "0.8.0", default-features = false, features = ["derive", "std"] }
24+
reqwest = { version = "0.12.15", features = ["zstd"] }
25+
26+
[dev-dependencies]
27+
similar-asserts = "1.7.0"
28+
29+
[lints]
30+
workspace = true

0 commit comments

Comments
 (0)