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

Commit

Permalink
Merge pull request #545 from cgwalters/fix-oci-with-tag
Browse files Browse the repository at this point in the history
container/encapsulate: Fix pushing to OCI directories with a tag
  • Loading branch information
cgwalters authored Sep 26, 2023
2 parents bf7137c + 4f52a22 commit 176519f
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 176519f

Please sign in to comment.