Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

Commit

Permalink
container/encapsulate: Fix pushing to OCI directories with a tag
Browse files Browse the repository at this point in the history
We need to support e.g.
`rpm-ostree compose container-encapsulate --format=oci manifest.yaml oci:foo:42`
  • Loading branch information
cgwalters committed Sep 25, 2023
1 parent 8dc1f95 commit 4f52a22
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lib/src/container/encapsulate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ fn build_oci(
/// such as `/foo/bar` will return `("/foo/bar"`, None)`, whereas
/// e.g. `/foo/bar:latest` will return `("/foo/bar", Some("latest"))`.
pub(crate) fn parse_oci_path_and_tag(path: &str) -> (&str, Option<&str>) {
match path.rsplit_once(':') {
match path.split_once(':') {
Some((path, tag)) => (path, Some(tag)),
None => (path, None),
}
Expand All @@ -331,6 +331,7 @@ async fn build_impl(
}
let digest = if dest.transport == Transport::OciDir {
let (path, tag) = parse_oci_path_and_tag(dest.name.as_str());
tracing::debug!("using OCI path={path} tag={tag:?}");
let _copied: ImageReference =
build_oci(repo, ostree_ref, Path::new(path), tag, config, opts)?;
None
Expand All @@ -355,7 +356,9 @@ async fn build_impl(
sigverify: SignatureSource::ContainerPolicyAllowInsecure,
imgref: dest.to_owned(),
};
let (_, digest) = super::unencapsulate::fetch_manifest(&imgref).await?;
let (_, digest) = super::unencapsulate::fetch_manifest(&imgref)
.await
.context("Querying manifest after push")?;
Ok(digest)
}
}
Expand Down Expand Up @@ -408,3 +411,16 @@ pub async fn encapsulate<S: AsRef<str>>(
) -> Result<String> {
build_impl(repo, ostree_ref.as_ref(), config, opts, dest).await
}

#[test]
fn test_parse_ocipath() {
let default = "/foo/bar";
let untagged = "/foo/bar:baz";
let tagged = "/foo/bar:baz:latest";
assert_eq!(parse_oci_path_and_tag(default), ("/foo/bar", None));
assert_eq!(
parse_oci_path_and_tag(tagged),
("/foo/bar", Some("baz:latest"))
);
assert_eq!(parse_oci_path_and_tag(untagged), ("/foo/bar", Some("baz")));
}

0 comments on commit 4f52a22

Please sign in to comment.