Package org.openrewrite.docker.trait
Interface DockerImageReference<T extends Docker.Instruction>
- Type Parameters:
T- The instruction type carrying the image reference (Docker.Fromfor aFROM, orDocker.Instructionfor aCOPY/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 ClassesModifier and TypeInterfaceDescriptionstatic classMatcher that finds image references inFROM,COPY --from, andADD --fromalike, yielding the sharedDockerImageReferencecontract.static enumReasons why an image may be considered unpinned. -
Method Summary
Modifier and TypeMethodDescriptionbooleandigestMatches(String pattern) 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.getTag()Returns the tag, or empty if no tag is specified.Returns the reason the referenced image is unpinned, or empty if it is pinned.booleanimageNameMatches(String pattern) Checks if the image name matches the given glob pattern.booleanReturns true if the referenced image is pinned by digest.booleanReturns true if the referenced image is unpinned (no tag or an explicit "latest" tag).booleantagMatches(String pattern) Checks if the tag matches the given glob pattern.withImageReference(String reference) Returns the instruction with its image reference replaced byreference(e.g.Returns the instruction with the tag of its image reference replaced bytag, preserving the image name and any digest.Methods inherited from interface org.openrewrite.trait.Trait
getCursor, getTree
-
Method Details
-
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
Returns the tag, or empty if no tag is specified. -
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
Optional<DockerImageReference.UnpinnedReason> getUnpinnedReason()Returns the reason the referenced image is unpinned, or empty if it is pinned. -
imageNameMatches
Checks if the image name matches the given glob pattern. -
tagMatches
Checks if the tag matches the given glob pattern. -
digestMatches
Checks if the digest matches the given glob pattern. -
withImageReference
Returns the instruction with its image reference replaced byreference(e.g."nginx:1.25"). -
withTag
Returns the instruction with the tag of its image reference replaced bytag, preserving the image name and any digest.
-