Skip to content

Commit 9df369b

Browse files
committed
cfsctl: Add 'ostree commit' subcommand
Creates an ostree commit from an existing composefs image in the repository. The image is specified by its object ID or refs/ name. Example workflow to create an ostree commit from an OCI image: IMAGE_ID=$(cfsctl oci compute-id myimage:latest) cfsctl ostree commit $IMAGE_ID --reference fedora/40/x86_64 Signed-off-by: Alexander Larsson <alexl@redhat.com>
1 parent 0aa435a commit 9df369b

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

  • crates/composefs-ctl/src

crates/composefs-ctl/src/lib.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,21 @@ enum OstreeCommand {
582582
#[arg(add = ArgValueCompleter::new(complete_ostree_refs))]
583583
name: String,
584584
},
585+
/// Create an ostree commit from a composefs image in the repository
586+
///
587+
/// The image is specified by its object ID or refs/ name (the same
588+
/// format used by `cfsctl mount` and `cfsctl image-objects`).
589+
Commit {
590+
/// Composefs image ID or refs/ name
591+
#[arg(add = ArgValueCompleter::new(complete_image_refs))]
592+
image: String,
593+
/// Ostree ref name to tag the commit with
594+
#[clap(long)]
595+
reference: Option<String>,
596+
/// One-line commit subject
597+
#[clap(long, default_value = "")]
598+
subject: String,
599+
},
585600
/// List all ostree commits in the repository
586601
#[clap(name = "images")]
587602
ListCommits,
@@ -1834,6 +1849,46 @@ where
18341849
OstreeCommand::Untag { ref name } => {
18351850
composefs_ostree::untag(&repo, name)?;
18361851
}
1852+
OstreeCommand::Commit {
1853+
ref image,
1854+
ref reference,
1855+
ref subject,
1856+
} => {
1857+
use std::time::{SystemTime, UNIX_EPOCH};
1858+
1859+
let (img_fd, _) = repo.open_image(image)?;
1860+
let mut img_buf = Vec::new();
1861+
std::fs::File::from(img_fd).read_to_end(&mut img_buf)?;
1862+
let fs = composefs::erofs::reader::erofs_to_filesystem(&img_buf)?;
1863+
1864+
let timestamp = SystemTime::now()
1865+
.duration_since(UNIX_EPOCH)
1866+
.unwrap_or_default()
1867+
.as_secs();
1868+
let mut commit_meta = composefs_ostree::ostree::CommitMetadata::default()
1869+
.subject(subject.as_str())
1870+
.timestamp(timestamp);
1871+
if let Some(ref_name) = reference {
1872+
commit_meta = commit_meta.add_metadata(
1873+
"ostree.ref-binding",
1874+
composefs_ostree::ostree::MetadataValue::StringArray(vec![
1875+
ref_name.clone(),
1876+
]),
1877+
);
1878+
}
1879+
1880+
let (verity, commit_id) = composefs_ostree::commit_filesystem(
1881+
&repo,
1882+
&fs,
1883+
commit_meta,
1884+
reference.as_deref(),
1885+
)?;
1886+
println!("commit {commit_id}");
1887+
println!("verity {}", verity.to_hex());
1888+
if let Some(ref_name) = reference {
1889+
println!("tagged {ref_name}");
1890+
}
1891+
}
18371892
OstreeCommand::ListCommits => {
18381893
let commits = composefs_ostree::list_commits(&repo)?;
18391894
if commits.is_empty() {

0 commit comments

Comments
 (0)