Skip to content

Commit da310b0

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 cb4e888 commit da310b0

File tree

8 files changed

+1615
-1
lines changed

8 files changed

+1615
-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
@@ -98,6 +98,31 @@ enum OciCommand {
9898
},
9999
}
100100

101+
#[cfg(feature = "ostree")]
102+
#[derive(Debug, Subcommand)]
103+
enum OstreeCommand {
104+
PullLocal {
105+
repo_path: PathBuf,
106+
ostree_ref: String,
107+
#[clap(long)]
108+
base_name: Option<String>,
109+
},
110+
Pull {
111+
repo_url: String,
112+
ostree_ref: String,
113+
#[clap(long)]
114+
base_name: Option<String>,
115+
},
116+
CreateImage {
117+
commit_name: String,
118+
#[clap(long)]
119+
image_name: Option<String>,
120+
},
121+
Inspect {
122+
commit_name: String,
123+
},
124+
}
125+
101126
#[derive(Debug, Subcommand)]
102127
enum Command {
103128
/// Take a transaction lock on the repository.
@@ -120,6 +145,12 @@ enum Command {
120145
#[clap(subcommand)]
121146
cmd: OciCommand,
122147
},
148+
/// Commands for dealing with OSTree commits
149+
#[cfg(feature = "ostree")]
150+
Ostree {
151+
#[clap(subcommand)]
152+
cmd: OstreeCommand,
153+
},
123154
/// Mounts a composefs, possibly enforcing fsverity of the image
124155
Mount {
125156
/// the name of the image to mount, either an fs-verity hash or prefixed with 'ref/'
@@ -317,6 +348,50 @@ async fn main() -> Result<()> {
317348
create_dir_all(state.join("etc/work"))?;
318349
}
319350
},
351+
#[cfg(feature = "ostree")]
352+
Command::Ostree { cmd: ostree_cmd } => match ostree_cmd {
353+
OstreeCommand::PullLocal {
354+
ref repo_path,
355+
ref ostree_ref,
356+
base_name,
357+
} => {
358+
let verity = composefs_ostree::pull_local(
359+
&Arc::new(repo),
360+
repo_path,
361+
ostree_ref,
362+
base_name.as_deref(),
363+
)
364+
.await?;
365+
366+
println!("verity {}", verity.to_hex());
367+
}
368+
OstreeCommand::Pull {
369+
ref repo_url,
370+
ref ostree_ref,
371+
base_name,
372+
} => {
373+
let verity = composefs_ostree::pull(
374+
&Arc::new(repo),
375+
repo_url,
376+
ostree_ref,
377+
base_name.as_deref(),
378+
)
379+
.await?;
380+
381+
println!("verity {}", verity.to_hex());
382+
}
383+
OstreeCommand::CreateImage {
384+
ref commit_name,
385+
ref image_name,
386+
} => {
387+
let mut fs = composefs_ostree::create_filesystem(&repo, commit_name)?;
388+
let image_id = fs.commit_image(&repo, image_name.as_deref())?;
389+
println!("{}", image_id.to_id());
390+
}
391+
OstreeCommand::Inspect { ref commit_name } => {
392+
composefs_ostree::inspect(&repo, commit_name)?;
393+
}
394+
},
320395
Command::ComputeId {
321396
ref path,
322397
bootable,

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)