Class DockerFrom

java.lang.Object
org.openrewrite.docker.trait.DockerFrom
All Implemented Interfaces:
org.openrewrite.trait.Trait<Docker.From>

public class DockerFrom extends Object implements org.openrewrite.trait.Trait<Docker.From>
A trait representing a Docker base image from a FROM instruction. Provides semantic access to image name, tag, digest, platform, and stage name, along with matching capabilities that handle environment variables.
  • Constructor Details

    • DockerFrom

      public DockerFrom()
  • Method Details

    • getImageName

      public @Nullable String getImageName()
      Returns the image name (without tag or digest). Environment variables are preserved in their original form.
      Returns:
      The image name, or null if it contains unresolvable variables
    • getTag

      public @Nullable String getTag()
      Returns the tag, or null if no tag is specified. Environment variables are preserved in their original form.
      Returns:
      The tag, or null
    • getDigest

      public @Nullable String getDigest()
      Returns the digest, or null if no digest is specified. Environment variables are preserved in their original form.
      Returns:
      The digest, or null
    • getPlatform

      public @Nullable String getPlatform()
      Returns the platform flag value, or null if not specified.
      Returns:
      The platform (e.g., "linux/amd64"), or null
    • getStageName

      public @Nullable String getStageName()
      Returns the stage name (AS alias), or null if not specified.
      Returns:
      The stage name, or null
    • isScratch

      public boolean isScratch()
      Returns true if this is the special "scratch" base image.
      Returns:
      true if the image is "scratch"
    • isUnpinned

      public boolean isUnpinned()
      Returns true if this image is unpinned (no tag, uses "latest" tag, or has no digest). Images with a digest are considered pinned regardless of tag.
      Returns:
      true if the image is unpinned
    • getUnpinnedReason

      public @Nullable DockerFrom.UnpinnedReason getUnpinnedReason()
      Returns the reason this image is unpinned, or null if it's pinned. Images with a digest are considered pinned. Images with environment variables in the tag are conservatively considered pinned (we can't determine the value).
      Returns:
      The reason for being unpinned, or null if pinned
    • getQuoteStyle

      public @Nullable Docker.Literal.QuoteStyle getQuoteStyle()
      Returns the quote style used for the image name, if any.
      Returns:
      The quote style, or null if unquoted
    • imageNameMatches

      public boolean imageNameMatches(String pattern)
      Checks if the image name (without tag/digest) matches the given glob pattern.
      Parameters:
      pattern - The glob pattern to match against
      Returns:
      true if the image name matches
    • tagMatches

      public boolean tagMatches(String pattern)
      Checks if the tag matches the given glob pattern.
      Parameters:
      pattern - The glob pattern to match against
      Returns:
      true if the tag matches, false if no tag or doesn't match
    • digestMatches

      public boolean digestMatches(String pattern)
      Checks if the digest matches the given glob pattern.
      Parameters:
      pattern - The glob pattern to match against
      Returns:
      true if the digest matches, false if no digest or doesn't match