Skip to content

Commit 8d8c6b2

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 082d874 commit 8d8c6b2

8 files changed

Lines changed: 1842 additions & 1 deletion

File tree

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ composefs-ioctls = { version = "0.4.0", path = "crates/composefs-ioctls", defaul
3838
composefs-oci = { version = "0.4.0", path = "crates/composefs-oci", default-features = false }
3939
composefs-boot = { version = "0.4.0", path = "crates/composefs-boot", default-features = false }
4040
composefs-http = { version = "0.4.0", path = "crates/composefs-http", default-features = false }
41+
composefs-ostree = { version = "0.4.0", path = "crates/composefs-ostree", default-features = false }
4142
cap-std-ext = "5.1.2"
4243
ocidir = "0.7.2"
4344

crates/composefs-ctl/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ name = "cfsctl"
1717
path = "src/main.rs"
1818

1919
[features]
20-
default = ['pre-6.15', 'oci', 'containers-storage']
20+
default = ['pre-6.15', 'oci', 'containers-storage', 'ostree']
2121
http = ['composefs-http']
2222
oci = ['composefs-oci', 'composefs-oci/varlink']
2323
containers-storage = ['composefs-oci/containers-storage', 'cstorage']
24+
ostree = ['composefs-ostree']
2425
rhel9 = ['composefs/rhel9']
2526
'pre-6.15' = ['composefs/pre-6.15']
2627

@@ -34,6 +35,7 @@ composefs-boot = { workspace = true }
3435
composefs-oci = { workspace = true, optional = true, features = ["boot"] }
3536
composefs-http = { workspace = true, optional = true }
3637
cstorage = { package = "composefs-storage", path = "../composefs-storage", version = "0.4.0", features = ["userns-helper"], optional = true }
38+
composefs-ostree = { workspace = true, optional = true }
3739
env_logger = { version = "0.11.0", default-features = false }
3840
hex = { version = "0.4.0", default-features = false }
3941
indicatif = { version = "0.17.0", default-features = false }

crates/composefs-ctl/src/lib.rs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,31 @@ enum OciCommand {
501501
},
502502
}
503503

504+
#[cfg(feature = "ostree")]
505+
#[derive(Debug, Subcommand)]
506+
enum OstreeCommand {
507+
PullLocal {
508+
ostree_repo_path: PathBuf,
509+
ostree_ref: String,
510+
#[clap(long)]
511+
base_name: Option<String>,
512+
},
513+
Pull {
514+
ostree_repo_url: String,
515+
ostree_ref: String,
516+
#[clap(long)]
517+
base_name: Option<String>,
518+
},
519+
CreateImage {
520+
commit_name: String,
521+
#[clap(long)]
522+
image_name: Option<String>,
523+
},
524+
Inspect {
525+
commit_name: String,
526+
},
527+
}
528+
504529
/// Common options for reading a filesystem from a path
505530
#[derive(Debug, Parser)]
506531
struct FsReadOptions {
@@ -570,6 +595,11 @@ enum Command {
570595
#[clap(subcommand)]
571596
cmd: OciCommand,
572597
},
598+
#[cfg(feature = "ostree")]
599+
Ostree {
600+
#[clap(subcommand)]
601+
cmd: OstreeCommand,
602+
},
573603
/// Mounts a composefs image, possibly enforcing fsverity of the image
574604
Mount {
575605
/// the name of the image to mount, either an fs-verity hash or prefixed with 'ref/'
@@ -1566,6 +1596,50 @@ where
15661596
unreachable!("oci varlink is handled before opening a repository");
15671597
}
15681598
},
1599+
#[cfg(feature = "ostree")]
1600+
Command::Ostree { cmd: ostree_cmd } => match ostree_cmd {
1601+
OstreeCommand::PullLocal {
1602+
ref ostree_repo_path,
1603+
ref ostree_ref,
1604+
base_name,
1605+
} => {
1606+
let verity = composefs_ostree::pull_local(
1607+
&repo,
1608+
ostree_repo_path,
1609+
ostree_ref,
1610+
base_name.as_deref(),
1611+
)
1612+
.await?;
1613+
1614+
println!("verity {}", verity.to_hex());
1615+
}
1616+
OstreeCommand::Pull {
1617+
ref ostree_repo_url,
1618+
ref ostree_ref,
1619+
base_name,
1620+
} => {
1621+
let verity = composefs_ostree::pull(
1622+
&repo,
1623+
ostree_repo_url,
1624+
ostree_ref,
1625+
base_name.as_deref(),
1626+
)
1627+
.await?;
1628+
1629+
println!("verity {}", verity.to_hex());
1630+
}
1631+
OstreeCommand::CreateImage {
1632+
ref commit_name,
1633+
ref image_name,
1634+
} => {
1635+
let fs = composefs_ostree::create_filesystem(&repo, commit_name)?;
1636+
let image_id = fs.commit_image(&repo, image_name.as_deref())?;
1637+
println!("{}", image_id.to_id());
1638+
}
1639+
OstreeCommand::Inspect { ref commit_name } => {
1640+
composefs_ostree::inspect(&repo, commit_name)?;
1641+
}
1642+
},
15691643
Command::CreateImage {
15701644
fs_opts,
15711645
ref image_name,

crates/composefs-ostree/Cargo.toml

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

0 commit comments

Comments
 (0)