Skip to content

Commit cc33c5f

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 commit splitstream containing all the remaining ostree objects and file data. From the splitstream we can create an image. When pulling a commit, a base commit (i.e. "the previous version" can be specified. Any objects in that base commit 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 commit. 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 commit) * Local ostree repos only support archive mode * There is no GPG validation on ostree pull Signed-off-by: Alexander Larsson <alexl@redhat.com>
1 parent 368dce8 commit cc33c5f

File tree

8 files changed

+1601
-1
lines changed

8 files changed

+1601
-1
lines changed

Cargo.toml

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

2425
[profile.dev.package.sha2]
2526
# 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
@@ -111,6 +111,31 @@ enum OciCommand {
111111
},
112112
}
113113

114+
#[cfg(feature = "ostree")]
115+
#[derive(Debug, Subcommand)]
116+
enum OstreeCommand {
117+
PullLocal {
118+
ostree_repo_path: PathBuf,
119+
ostree_ref: String,
120+
#[clap(long)]
121+
base_name: Option<String>,
122+
},
123+
Pull {
124+
ostree_repo_url: String,
125+
ostree_ref: String,
126+
#[clap(long)]
127+
base_name: Option<String>,
128+
},
129+
CreateImage {
130+
commit_name: String,
131+
#[clap(long)]
132+
image_name: Option<String>,
133+
},
134+
Inspect {
135+
commit_name: String,
136+
},
137+
}
138+
114139
/// Common options for reading a filesystem from a path
115140
#[derive(Debug, Parser)]
116141
struct FsReadOptions {
@@ -144,6 +169,12 @@ enum Command {
144169
#[clap(subcommand)]
145170
cmd: OciCommand,
146171
},
172+
/// Commands for dealing with OSTree commits
173+
#[cfg(feature = "ostree")]
174+
Ostree {
175+
#[clap(subcommand)]
176+
cmd: OstreeCommand,
177+
},
147178
/// Mounts a composefs, possibly enforcing fsverity of the image
148179
Mount {
149180
/// the name of the image to mount, either an fs-verity hash or prefixed with 'ref/'
@@ -367,6 +398,50 @@ where
367398
let id = fs.compute_image_id();
368399
println!("{}", id.to_hex());
369400
}
401+
#[cfg(feature = "ostree")]
402+
Command::Ostree { cmd: ostree_cmd } => match ostree_cmd {
403+
OstreeCommand::PullLocal {
404+
ref ostree_repo_path,
405+
ref ostree_ref,
406+
base_name,
407+
} => {
408+
let verity = composefs_ostree::pull_local(
409+
&Arc::new(repo),
410+
ostree_repo_path,
411+
ostree_ref,
412+
base_name.as_deref(),
413+
)
414+
.await?;
415+
416+
println!("verity {}", verity.to_hex());
417+
}
418+
OstreeCommand::Pull {
419+
ref ostree_repo_url,
420+
ref ostree_ref,
421+
base_name,
422+
} => {
423+
let verity = composefs_ostree::pull(
424+
&Arc::new(repo),
425+
ostree_repo_url,
426+
ostree_ref,
427+
base_name.as_deref(),
428+
)
429+
.await?;
430+
431+
println!("verity {}", verity.to_hex());
432+
}
433+
OstreeCommand::CreateImage {
434+
ref commit_name,
435+
ref image_name,
436+
} => {
437+
let fs = composefs_ostree::create_filesystem(&repo, commit_name)?;
438+
let image_id = fs.commit_image(&repo, image_name.as_deref())?;
439+
println!("{}", image_id.to_id());
440+
}
441+
OstreeCommand::Inspect { ref commit_name } => {
442+
composefs_ostree::inspect(&repo, commit_name)?;
443+
}
444+
},
370445
Command::CreateImage {
371446
fs_opts,
372447
ref image_name,

crates/composefs-ostree/Cargo.toml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
rustix = { version = "1.0.0", default-features = false, features = ["fs", "mount", "process", "std"] }
21+
sha2 = { version = "0.10.1", default-features = false }
22+
zerocopy = { version = "0.8.0", default-features = false, features = ["derive", "std"] }
23+
reqwest = { version = "0.12.15", features = ["zstd"] }
24+
25+
[dev-dependencies]
26+
similar-asserts = "1.7.0"
27+
28+
[lints]
29+
workspace = true

0 commit comments

Comments
 (0)