Skip to content

Commit

Permalink
oci: add a meta-layer command
Browse files Browse the repository at this point in the history
This is a quick hack to get the hidden composefs-meta layer out of a
container image.
  • Loading branch information
allisonkarlitskaya committed Oct 30, 2024
1 parent 78d3670 commit b0858d3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/bin/cfsctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ enum OciCommand {
name: String,
mountpoint: String,
},
MetaLayer {
name: String,
},
}

#[derive(Debug, Subcommand)]
Expand Down Expand Up @@ -150,6 +153,9 @@ fn main() -> Result<()> {
} => {
oci::mount(&repo, name, mountpoint, None)?;
}
OciCommand::MetaLayer { ref name } => {
oci::meta_layer(&repo, name, None)?;
}
},
Command::Mount { name, mountpoint } => {
repo.mount(&name, &mountpoint)?;
Expand Down
17 changes: 17 additions & 0 deletions src/oci/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,20 @@ pub fn mount(
};
repo.mount(id, mountpoint)
}

pub fn meta_layer(repo: &Repository, name: &str, verity: Option<&Sha256HashValue>) -> Result<()> {
let (config, refs) = open_config(repo, name, verity)?;

let ids = config.rootfs().diff_ids();
if ids.len() >= 3 {
let layer_sha256 = sha256_from_digest(&ids[ids.len() - 2])?;
let layer_verity = refs.lookup(&layer_sha256).context("bzzt")?;
repo.merge_splitstream(
&hex::encode(layer_sha256),
Some(layer_verity),
&mut std::io::stdout(),
)
} else {
bail!("No meta layer here");
}
}

0 comments on commit b0858d3

Please sign in to comment.