Skip to main content

detect_from_image

Function detect_from_image 

Source
pub fn detect_from_image(image: &str) -> Option<StackLabel>
Expand description

Detect a stack label from a container or artifact image name.

The detector matches the base image name after removing any registry, namespace, tag, or digest. Matching is ASCII case-insensitive.

Most language runtime images, such as node, python, and php, match only their exact name, so python-linter or rubygems-mirror are not runtimes. Database and service images, plus the openjdk, eclipse-temurin, amazoncorretto, and dotnet runtime images, match a prefix followed by the end of the name or a separator (-, _, .): mysql-server is MySQL and redis-sentinel is Redis, while postgrest is not PostgreSQL and redisinsight is not Redis. Prefix matches are rejected when a later name segment marks a companion image such as exporter, dashboards, operator, admin, or ui, so postgres-exporter and opensearch-dashboards produce no label. Images under the dotnet or mssql registry namespaces are .NET and SQL Server whatever their base name.

§Examples

use what_stack::detect_from_image;

assert_eq!(detect_from_image("postgres:16").expect("known image"), "PostgreSQL");
assert_eq!(
    detect_from_image("mcr.microsoft.com/dotnet/aspnet:8.0").expect("known image"),
    ".NET",
);
assert_eq!(detect_from_image("prom/node-exporter:latest"), None);
assert_eq!(detect_from_image("prometheuscommunity/postgres-exporter"), None);
assert_eq!(detect_from_image("postgrest/postgrest"), None);

§Limits

This is intentionally a built-in rule set. The crate does not read custom image rules or inspect image manifests.