From 4f52a22ba323f03a84784a01c672dcc28453655f Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Mon, 25 Sep 2023 09:30:45 -0400 Subject: [PATCH] container/encapsulate: Fix pushing to OCI directories with a tag We need to support e.g. `rpm-ostree compose container-encapsulate --format=oci manifest.yaml oci:foo:42` --- lib/src/container/encapsulate.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/src/container/encapsulate.rs b/lib/src/container/encapsulate.rs index 81efa070..0b1ca300 100644 --- a/lib/src/container/encapsulate.rs +++ b/lib/src/container/encapsulate.rs @@ -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), } @@ -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 @@ -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) } } @@ -408,3 +411,16 @@ pub async fn encapsulate>( ) -> Result { 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"))); +}