Package org.openrewrite.docker.trait
Class DockerFrom
java.lang.Object
org.openrewrite.docker.trait.DockerFrom
- All Implemented Interfaces:
DockerImageReference<Docker.From>,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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classMatcher for DockerImage traits with builder-style configuration.Nested classes/interfaces inherited from interface org.openrewrite.docker.trait.DockerImageReference
DockerImageReference.UnpinnedReason -
Constructor Summary
Constructors -
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).@Nullable StringReturns the platform flag value, or null if not specified.@Nullable Docker.Literal.QuoteStyleReturns the quote style used for the image name, if any.@Nullable StringReturns the stage name (AS alias), or null if not specified.getTag()Returns the tag, or empty if no tag is specified.Returns the reason this image is unpinned, or empty if it's pinned.booleanimageNameMatches(String pattern) Checks if the image name (without tag/digest) matches the given glob pattern.booleanReturns true if this image is pinned by digest (carries an@sha256:...reference), regardless of tag.booleanReturns true if this is the special "scratch" base image.booleanReturns true if this image is unpinned (no tag, uses "latest" tag, or has no digest).booleantagMatches(String pattern) Checks if the tag matches the given glob pattern.withImageReference(String reference) Returns the FROM instruction with its image reference replaced byreference(e.g.Returns the FROM instruction with the tag of its image reference replaced bytag, preserving the image name and any digest.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.openrewrite.trait.Trait
getCursor, getTree
-
Constructor Details
-
DockerFrom
public DockerFrom()
-
-
Method Details
-
getImageName
Returns the image name (without tag or digest). Environment variables are preserved in their original form.- Specified by:
getImageNamein interfaceDockerImageReference<Docker.From>- Returns:
- The image name
-
getTag
Returns the tag, or empty if no tag is specified. Environment variables are preserved in their original form.- Specified by:
getTagin interfaceDockerImageReference<Docker.From>- Returns:
- The tag, or empty
-
getDigest
Returns the digest, or empty if no digest is specified. Environment variables are preserved in their original form.- Specified by:
getDigestin interfaceDockerImageReference<Docker.From>- Returns:
- The digest, or empty
-
getPlatform
Returns the platform flag value, or null if not specified.- Returns:
- The platform (e.g., "linux/amd64"), or null
-
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:
isUnpinnedin interfaceDockerImageReference<Docker.From>- Returns:
- true if the image is unpinned
-
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:
getUnpinnedReasonin interfaceDockerImageReference<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 fromisUnpinned(), 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:
isDigestPinnedin interfaceDockerImageReference<Docker.From>- Returns:
- true if a digest is present
-
getQuoteStyle
Returns the quote style used for the image name, if any.- Returns:
- The quote style, or null if unquoted
-
imageNameMatches
Checks if the image name (without tag/digest) matches the given glob pattern.- Specified by:
imageNameMatchesin interfaceDockerImageReference<Docker.From>- Parameters:
pattern- The glob pattern to match against- Returns:
- true if the image name matches
-
tagMatches
Checks if the tag matches the given glob pattern.- Specified by:
tagMatchesin interfaceDockerImageReference<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
Checks if the digest matches the given glob pattern.- Specified by:
digestMatchesin interfaceDockerImageReference<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
Returns the FROM instruction with its image reference replaced byreference(e.g."nginx:1.25"), decomposing it into the structured image name, tag, and digest while preserving the original prefix.- Specified by:
withImageReferencein interfaceDockerImageReference<Docker.From>
-
withTag
Returns the FROM instruction with the tag of its image reference replaced bytag, preserving the image name and any digest.- Specified by:
withTagin interfaceDockerImageReference<Docker.From>
-