parse_image_ref

Function parse_image_ref 

Source
pub fn parse_image_ref(
    image_ref: &str,
) -> MonocoreResult<(String, String, String)>
Expand description

Parses an OCI image reference (e.g. “ubuntu:latest” or “registry.example.com/org/image:tag”) into its components and generates a filesystem-safe name.

Returns (repository, tag, fs_safe_name) where:

  • repository is the part before the last ‘:’ (excluding registry port colons)
  • tag is the part after the last ‘:’ (defaults to “latest” if no tag specified)
  • fs_safe_name is the sanitized filesystem name

Automatically qualifies unqualified image references with “library/”, similar to Docker. For example, “ubuntu” becomes “library/ubuntu”.

§Examples

use monocore::utils::parse_image_ref;

assert_eq!(parse_image_ref("ubuntu:latest").unwrap(), ("library/ubuntu".to_string(), "latest".to_string(), "library_ubuntu__latest".to_string()));
assert_eq!(parse_image_ref("ubuntu").unwrap(), ("library/ubuntu".to_string(), "latest".to_string(), "library_ubuntu__latest".to_string()));
assert_eq!(
    parse_image_ref("registry.com/org/image:1.0").unwrap(),
    ("registry.com/org/image".to_string(), "1.0".to_string(), "registry.com_org_image__1.0".to_string())
);