Interface DockerImageReference<T extends Docker.Instruction>

Type Parameters:
T - The instruction type carrying the image reference (Docker.From for a FROM, or Docker.Instruction for a COPY/ADD).
All Superinterfaces:
org.openrewrite.trait.Trait<T>
All Known Implementing Classes:
DockerCopyFrom, DockerFrom

public interface DockerImageReference<T extends Docker.Instruction> extends org.openrewrite.trait.Trait<T>
A trait representing an image reference anywhere in a Dockerfile: the base image of a FROM instruction (see DockerFrom) or the image carried by the --from flag of a COPY / ADD instruction (see DockerCopyFrom).

This is the common contract shared by both concrete traits, providing semantic access to the image name, tag, and digest, pinning classification, glob matching, and the ability to update the reference. Location-specific concepts (platform, stage name, scratch, stage references) live on the concrete traits.

Use DockerImageReference.Matcher to find and update image references regardless of where they occur.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static class 
    Matcher that finds image references in FROM, COPY --from, and ADD --from alike, yielding the shared DockerImageReference contract.
    static enum 
    Reasons why an image may be considered unpinned.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Checks if the digest matches the given glob pattern.
    Returns the digest, or empty if no digest is specified.
    Returns the image name (without tag or digest), or empty if the reference does not resolve to an external image (e.g.
    Returns the tag, or empty if no tag is specified.
    Returns the reason the referenced image is unpinned, or empty if it is pinned.
    boolean
    Checks if the image name matches the given glob pattern.
    boolean
    Returns true if the referenced image is pinned by digest.
    boolean
    Returns true if the referenced image is unpinned (no tag or an explicit "latest" tag).
    boolean
    tagMatches(String pattern)
    Checks if the tag matches the given glob pattern.
    Returns the instruction with its image reference replaced by reference (e.g.
    Returns the instruction with the tag of its image reference replaced by tag, preserving the image name and any digest.

    Methods inherited from interface org.openrewrite.trait.Trait

    getCursor, getTree
  • Method Details

    • getImageName

      Optional<String> getImageName()
      Returns the image name (without tag or digest), or empty if the reference does not resolve to an external image (e.g. a build-stage reference).
    • getTag

      Optional<String> getTag()
      Returns the tag, or empty if no tag is specified.
    • getDigest

      Optional<String> getDigest()
      Returns the digest, or empty if no digest is specified.
    • isDigestPinned

      boolean isDigestPinned()
      Returns true if the referenced image is pinned by digest.
    • isUnpinned

      boolean isUnpinned()
      Returns true if the referenced image is unpinned (no tag or an explicit "latest" tag).
    • getUnpinnedReason

      Returns the reason the referenced image is unpinned, or empty if it is pinned.
    • imageNameMatches

      boolean imageNameMatches(String pattern)
      Checks if the image name matches the given glob pattern.
    • tagMatches

      boolean tagMatches(String pattern)
      Checks if the tag matches the given glob pattern.
    • digestMatches

      boolean digestMatches(String pattern)
      Checks if the digest matches the given glob pattern.
    • withImageReference

      T withImageReference(String reference)
      Returns the instruction with its image reference replaced by reference (e.g. "nginx:1.25").
    • withTag

      T withTag(String tag)
      Returns the instruction with the tag of its image reference replaced by tag, preserving the image name and any digest.