Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encapsulate: Add --copymeta-opt #4222

Merged
merged 1 commit into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions rust/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ struct ContainerEncapsulateOpts {
#[clap(name = "copymeta", long)]
copy_meta_keys: Vec<String>,

/// Propagate an optionally-present OSTree commit metadata key to container label
#[clap(name = "copymeta-opt", long)]
copy_meta_opt_keys: Vec<String>,

/// Corresponds to the Dockerfile `CMD` instruction.
#[clap(long)]
cmd: Option<Vec<String>>,
Expand Down Expand Up @@ -382,6 +386,7 @@ pub fn container_encapsulate(args: Vec<String>) -> CxxResult<()> {
let mut copy_meta_keys = opt.copy_meta_keys;
// Default to copying the input hash to support cheap change detection
copy_meta_keys.push("rpmostree.inputhash".to_string());
let copy_meta_opt_keys = opt.copy_meta_opt_keys;

let config = Config {
labels: Some(labels),
Expand All @@ -394,6 +399,7 @@ pub fn container_encapsulate(args: Vec<String>) -> CxxResult<()> {
};
let opts = ExportOpts {
copy_meta_keys,
copy_meta_opt_keys,
max_layers: opt.max_layers,
format,
..Default::default()
Expand Down
8 changes: 5 additions & 3 deletions tests/encapsulate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ ostree container unencapsulate --write-ref=testref --repo=repo ostree-remote-reg
# Re-pack it as a (chunked) container

rpm-ostree compose container-encapsulate --repo=repo \
--label=foo=bar --label baz=blah \
--label=foo=bar --label baz=blah --copymeta-opt fedora-coreos.stream --copymeta-opt nonexistent.key \
testref oci:test.oci
skopeo inspect oci:test.oci | jq -r .Labels.foo > labels.txt
grep -qFe bar labels.txt
skopeo inspect oci:test.oci | jq -r .Labels > labels.json
for label in foo baz 'fedora-coreos.stream'; do
jq -re ".\"${label}\"" < labels.json
done
echo ok