Package com.google.cloud.tools.jib.api
Class ImageReference
- java.lang.Object
-
- com.google.cloud.tools.jib.api.ImageReference
-
public class ImageReference extends java.lang.Object
Represents an image reference.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object other)
java.util.Optional<java.lang.String>
getDigest()
Gets the digest portion of theImageReference
.java.lang.String
getQualifier()
Gets the digest portion of theImageReference
if set, else returns the tag.java.lang.String
getRegistry()
Gets the registry portion of theImageReference
.java.lang.String
getRepository()
Gets the repository portion of theImageReference
.java.util.Optional<java.lang.String>
getTag()
Gets the tag portion of theImageReference
.int
hashCode()
static boolean
isDefaultTag(java.lang.String tag)
Returnstrue
iftag
is the default tag (latest
);false
if not.boolean
isScratch()
static boolean
isValidDigest(java.lang.String digest)
Returnstrue
ifdigest
is a valid digest string.static boolean
isValidRegistry(java.lang.String registry)
Returnstrue
ifregistry
is a valid registry string.static boolean
isValidRepository(java.lang.String repository)
Returnstrue
ifrepository
is a valid repository string.static boolean
isValidTag(java.lang.String tag)
Returnstrue
iftag
is a valid tag string.static ImageReference
of(java.lang.String registry, java.lang.String repository, java.lang.String qualifier)
Constructs anImageReference
from the image reference components, consisting of an optional registry, a repository, and an optional tag.static ImageReference
of(java.lang.String registry, java.lang.String repository, java.lang.String tag, java.lang.String digest)
Constructs anImageReference
from the image reference components, consisting of an optional registry, a repository, an optional tag, and an optional digest.static ImageReference
parse(java.lang.String reference)
Parses a stringreference
into anImageReference
.static ImageReference
scratch()
Constructs anImageReference
with an empty registry and tag component, and repository set to "scratch".java.lang.String
toString()
Stringifies theImageReference
.java.lang.String
toStringWithQualifier()
Stringifies theImageReference
.boolean
usesDefaultTag()
ImageReference
withQualifier(java.lang.String newQualifier)
Gets anImageReference
with the same registry and repository, but a different tag or digest.
-
-
-
Method Detail
-
parse
public static ImageReference parse(java.lang.String reference) throws InvalidImageReferenceException
Parses a stringreference
into anImageReference
.Image references should generally be in the form:
<registry>/<repository>:<tag>
For example, an image reference could begcr.io/k8s-skaffold/skaffold:v1.20.0
.See https://docs.docker.com/engine/reference/commandline/tag/#extended-description for a description of valid image reference format. Note, however, that the image reference is referred confusingly as
tag
on that page.- Parameters:
reference
- the string to parse- Returns:
- an
ImageReference
parsed from the string - Throws:
InvalidImageReferenceException
- ifreference
is formatted incorrectly
-
of
public static ImageReference of(@Nullable java.lang.String registry, java.lang.String repository, @Nullable java.lang.String qualifier)
Constructs anImageReference
from the image reference components, consisting of an optional registry, a repository, and an optional tag.- Parameters:
registry
- the image registry, ornull
to use the default registry (Docker Hub)repository
- the image repositoryqualifier
- the image tag or digest, ornull
to use the default tag (latest
).- Returns:
- an
ImageReference
built from the given registry, repository, and tag
-
of
public static ImageReference of(@Nullable java.lang.String registry, java.lang.String repository, @Nullable java.lang.String tag, @Nullable java.lang.String digest)
Constructs anImageReference
from the image reference components, consisting of an optional registry, a repository, an optional tag, and an optional digest. If neither the tag nor digest are specified,tag
will take on the default value oflatest
.- Parameters:
registry
- the image registry, ornull
to use the default registry (Docker Hub)repository
- the image repositorytag
- the image tag, ornull
to use the default tag (latest
)digest
- the image digest- Returns:
- an
ImageReference
built from the given registry, repository, and tag
-
scratch
public static ImageReference scratch()
Constructs anImageReference
with an empty registry and tag component, and repository set to "scratch".- Returns:
- an
ImageReference
with an empty registry and tag component, and repository set to "scratch"
-
isValidRegistry
public static boolean isValidRegistry(java.lang.String registry)
Returnstrue
ifregistry
is a valid registry string. For example, a valid registry could begcr.io
orlocalhost:5000
.- Parameters:
registry
- the registry to check- Returns:
true
if is a valid registry;false
otherwise
-
isValidRepository
public static boolean isValidRepository(java.lang.String repository)
Returnstrue
ifrepository
is a valid repository string. For example, a valid repository string could bemy-repository
ork8s-skaffold/skaffold
.- Parameters:
repository
- the repository to check- Returns:
true
if is a valid repository;false
otherwise
-
isValidTag
public static boolean isValidTag(java.lang.String tag)
Returnstrue
iftag
is a valid tag string. For example, a valid tag could bev120.5-release
.- Parameters:
tag
- the tag to check- Returns:
true
if is a valid tag;false
otherwise
-
isValidDigest
public static boolean isValidDigest(java.lang.String digest)
Returnstrue
ifdigest
is a valid digest string. For example, a valid digest could besha256:868fd30a0e47b8d8ac485df174795b5e2fe8a6c8f056cc707b232d65b8a1ab68
.- Parameters:
digest
- the digest to check- Returns:
true
if is a valid digest;false
otherwise
-
isDefaultTag
public static boolean isDefaultTag(@Nullable java.lang.String tag)
Returnstrue
iftag
is the default tag (latest
);false
if not.- Parameters:
tag
- the tag to check- Returns:
true
iftag
is the default tag (latest
);false
if not
-
getRegistry
public java.lang.String getRegistry()
Gets the registry portion of theImageReference
.- Returns:
- the registry host
-
getRepository
public java.lang.String getRepository()
Gets the repository portion of theImageReference
.- Returns:
- the repository
-
getTag
public java.util.Optional<java.lang.String> getTag()
Gets the tag portion of theImageReference
.- Returns:
- the optional tag
-
getDigest
public java.util.Optional<java.lang.String> getDigest()
Gets the digest portion of theImageReference
.- Returns:
- the optional digest
-
getQualifier
public java.lang.String getQualifier()
Gets the digest portion of theImageReference
if set, else returns the tag.- Returns:
- the digest if set, else the tag
-
usesDefaultTag
public boolean usesDefaultTag()
- Returns:
true
if uses the default tag;false
if not
-
isScratch
public boolean isScratch()
- Returns:
true
if theImageReference
is a scratch image;false
if not
-
withQualifier
public ImageReference withQualifier(java.lang.String newQualifier)
Gets anImageReference
with the same registry and repository, but a different tag or digest.- Parameters:
newQualifier
- the new tag or digest- Returns:
- an
ImageReference
with the same registry/repository and the new tag or digest
-
toString
public java.lang.String toString()
Stringifies theImageReference
.- Overrides:
toString
in classjava.lang.Object
- Returns:
- the image reference in Docker-readable format (inverse of
parse(java.lang.String)
)
-
toStringWithQualifier
public java.lang.String toStringWithQualifier()
Stringifies theImageReference
. If the digest is set, the result will include the digest and no tag. Otherwise, the result will include the tag, orlatest
if no tag is set.- Returns:
- the image reference in Docker-readable format including a qualifier.
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-