Class DockerFrom

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

public class DockerFrom extends Object implements DockerImageReference<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 Optional<String> getImageName()
      Returns the image name (without tag or digest). Environment variables are preserved in their original form.
      Specified by:
      getImageName in interface DockerImageReference<Docker.From>
      Returns:
      The image name
    • getTag

      public Optional<String> getTag()
      Returns the tag, or empty if no tag is specified. Environment variables are preserved in their original form.
      Specified by:
      getTag in interface DockerImageReference<Docker.From>
      Returns:
      The tag, or empty
    • getDigest

      public Optional<String> getDigest()
      Returns the digest, or empty if no digest is specified. Environment variables are preserved in their original form.
      Specified by:
      getDigest in interface DockerImageReference<Docker.From>
      Returns:
      The digest, or empty
    • 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.
      Specified by:
      isUnpinned in interface DockerImageReference<Docker.From>
      Returns:
      true if the image is unpinned
    • getUnpinnedReason

      public Optional<DockerImageReference.UnpinnedReason> getUnpinnedReason()
      Returns the reason this image is unpinned, or empty 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).
      Specified by:
      getUnpinnedReason in interface DockerImageReference<Docker.From>
      Returns:
      The reason for being unpinned, or empty if pinned
    • isDigestPinned

      public boolean isDigestPinned()
      Returns true if this image is pinned by digest (carries an @sha256:... reference), regardless of tag. This is distinct from isUnpinned(), which is tag-based: an image with a specific tag but no digest is not "unpinned", yet it is not digest-pinned either.
      Specified by:
      isDigestPinned in interface DockerImageReference<Docker.From>
      Returns:
      true if a digest is present
    • 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.
      Specified by:
      imageNameMatches in interface DockerImageReference<Docker.From>
      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.
      Specified by:
      tagMatches in interface DockerImageReference<Docker.From>
      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.
      Specified by:
      digestMatches in interface DockerImageReference<Docker.From>
      Parameters:
      pattern - The glob pattern to match against
      Returns:
      true if the digest matches, false if no digest or doesn't match
    • withImageReference

      public Docker.From withImageReference(String reference)
      Returns the FROM instruction with its image reference replaced by reference (e.g. "nginx:1.25"), decomposing it into the structured image name, tag, and digest while preserving the original prefix.
      Specified by:
      withImageReference in interface DockerImageReference<Docker.From>
    • withTag

      public Docker.From withTag(String tag)
      Returns the FROM instruction with the tag of its image reference replaced by tag, preserving the image name and any digest.
      Specified by:
      withTag in interface DockerImageReference<Docker.From>