Package com.google.cloud.tools.jib.api
Class Containerizer
- java.lang.Object
-
- com.google.cloud.tools.jib.api.Containerizer
-
public class Containerizer extends java.lang.Object
Configures how to containerize.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_APPLICATION_CACHE_DIRECTORY_NAME
static java.nio.file.Path
DEFAULT_BASE_CACHE_DIRECTORY
The default directory for caching the base image layers, in[user cache home]/google-cloud-tools-java/jib
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <E extends JibEvent>
ContainerizeraddEventHandler(java.lang.Class<E> eventType, java.util.function.Consumer<? super E> eventConsumer)
Containerizer
addEventHandler(java.util.function.Consumer<JibEvent> eventConsumer)
Adds theeventConsumer
to handle allJibEvent
types.Containerizer
addRegistryMirrors(java.lang.String registry, java.util.List<java.lang.String> mirrors)
Adds mirrors for a base image registry.Containerizer
setAllowInsecureRegistries(boolean allowInsecureRegistries)
Sets whether or not to allow communication over HTTP/insecure HTTPS.Containerizer
setAlwaysCacheBaseImage(boolean alwaysCacheBaseImage)
Controls the optimization which skips downloading base image layers that exist in a target registry.Containerizer
setApplicationLayersCache(java.nio.file.Path cacheDirectory)
Sets the directory to use for caching application layers.Containerizer
setBaseImageLayersCache(java.nio.file.Path cacheDirectory)
Sets the directory to use for caching base image layers.Containerizer
setExecutorService(java.util.concurrent.ExecutorService executorService)
Sets theExecutorService
Jib executes on.Containerizer
setOfflineMode(boolean offline)
Sets whether or not to run the build in offline mode.Containerizer
setToolName(java.lang.String toolName)
Sets the name of the tool that is using Jib Core.Containerizer
setToolVersion(java.lang.String toolVersion)
Sets the version of the tool that is using Jib Core.static Containerizer
to(DockerClient dockerClient, DockerDaemonImage dockerDaemonImage)
Gets a newContainerizer
that containerizes to a Docker daemon.static Containerizer
to(DockerDaemonImage dockerDaemonImage)
Gets a newContainerizer
that containerizes to a Docker daemon.static Containerizer
to(RegistryImage registryImage)
Gets a newContainerizer
that containerizes to a container registry.static Containerizer
to(TarImage tarImage)
Gets a newContainerizer
that containerizes to a tarball archive.Containerizer
withAdditionalTag(java.lang.String tag)
Adds an additional tag to tag the target image with.
-
-
-
Field Detail
-
DEFAULT_BASE_CACHE_DIRECTORY
public static final java.nio.file.Path DEFAULT_BASE_CACHE_DIRECTORY
The default directory for caching the base image layers, in[user cache home]/google-cloud-tools-java/jib
.
-
DEFAULT_APPLICATION_CACHE_DIRECTORY_NAME
public static final java.lang.String DEFAULT_APPLICATION_CACHE_DIRECTORY_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
to
public static Containerizer to(RegistryImage registryImage)
Gets a newContainerizer
that containerizes to a container registry.- Parameters:
registryImage
- theRegistryImage
that defines target container registry and credentials- Returns:
- a new
Containerizer
-
to
public static Containerizer to(DockerDaemonImage dockerDaemonImage)
Gets a newContainerizer
that containerizes to a Docker daemon.- Parameters:
dockerDaemonImage
- theDockerDaemonImage
that defines target Docker daemon- Returns:
- a new
Containerizer
-
to
public static Containerizer to(TarImage tarImage)
Gets a newContainerizer
that containerizes to a tarball archive.- Parameters:
tarImage
- theTarImage
that defines target output file- Returns:
- a new
Containerizer
-
to
public static Containerizer to(DockerClient dockerClient, DockerDaemonImage dockerDaemonImage)
Gets a newContainerizer
that containerizes to a Docker daemon.- Parameters:
dockerClient
- theDockerClient
to connectdockerDaemonImage
- theDockerDaemonImage
that defines target Docker daemon- Returns:
- a new
Containerizer
-
withAdditionalTag
public Containerizer withAdditionalTag(java.lang.String tag)
Adds an additional tag to tag the target image with. For example, the following would containerize to bothgcr.io/my-project/my-image:tag
andgcr.io/my-project/my-image:tag2
:Containerizer.to(RegistryImage.named("gcr.io/my-project/my-image:tag")).withAdditionalTag("tag2");
- Parameters:
tag
- the additional tag to push to- Returns:
- this
-
setExecutorService
public Containerizer setExecutorService(@Nullable java.util.concurrent.ExecutorService executorService)
Sets theExecutorService
Jib executes on. Jib, by default, usesExecutors.newCachedThreadPool()
.- Parameters:
executorService
- theExecutorService
- Returns:
- this
-
setBaseImageLayersCache
public Containerizer setBaseImageLayersCache(java.nio.file.Path cacheDirectory)
Sets the directory to use for caching base image layers. This cache can (and should) be shared between multiple images. The default base image layers cache directory is[user cache home]/google-cloud-tools-java/jib
(DEFAULT_BASE_CACHE_DIRECTORY
. This directory can be the same directory used forsetApplicationLayersCache(java.nio.file.Path)
.- Parameters:
cacheDirectory
- the cache directory- Returns:
- this
-
setApplicationLayersCache
public Containerizer setApplicationLayersCache(java.nio.file.Path cacheDirectory)
Sets the directory to use for caching application layers. This cache can be shared between multiple images. If not set, a temporary directory will be used as the application layers cache. This directory can be the same directory used forsetBaseImageLayersCache(java.nio.file.Path)
.- Parameters:
cacheDirectory
- the cache directory- Returns:
- this
-
addEventHandler
public <E extends JibEvent> Containerizer addEventHandler(java.lang.Class<E> eventType, java.util.function.Consumer<? super E> eventConsumer)
Adds theeventConsumer
to handle theJibEvent
with classeventType
. The order in which handlers are added is the order in which they are called when the event is dispatched.Note: Implementations of
eventConsumer
must be thread-safe.- Type Parameters:
E
- the type ofeventType
- Parameters:
eventType
- the event type thateventConsumer
should handleeventConsumer
- the event handler- Returns:
- this
-
addEventHandler
public Containerizer addEventHandler(java.util.function.Consumer<JibEvent> eventConsumer)
Adds theeventConsumer
to handle allJibEvent
types. SeeaddEventHandler(Class, Consumer)
for more details.- Parameters:
eventConsumer
- the event handler- Returns:
- this
-
setAllowInsecureRegistries
public Containerizer setAllowInsecureRegistries(boolean allowInsecureRegistries)
Sets whether or not to allow communication over HTTP/insecure HTTPS.- Parameters:
allowInsecureRegistries
- iftrue
, insecure connections will be allowed- Returns:
- this
-
setOfflineMode
public Containerizer setOfflineMode(boolean offline)
Sets whether or not to run the build in offline mode. In offline mode, the base image is retrieved from the cache instead of pulled from a registry, and the build will fail if the base image is not in the cache or if the target is an image registry.- Parameters:
offline
- iftrue
, the build will run in offline mode- Returns:
- this
-
setToolName
public Containerizer setToolName(java.lang.String toolName)
Sets the name of the tool that is using Jib Core. The tool name is sent as part of theUser-Agent
in registry requests and set as thecreated_by
in the container layer history. Defaults tojib-core
.- Parameters:
toolName
- the name of the tool using this library- Returns:
- this
-
setToolVersion
public Containerizer setToolVersion(@Nullable java.lang.String toolVersion)
Sets the version of the tool that is using Jib Core. The tool version is sent as part of theUser-Agent
in registry requests and set as thecreated_by
in the container layer history. Defaults to the current version of jib-core.- Parameters:
toolVersion
- the name of the tool using this library- Returns:
- this
-
setAlwaysCacheBaseImage
public Containerizer setAlwaysCacheBaseImage(boolean alwaysCacheBaseImage)
Controls the optimization which skips downloading base image layers that exist in a target registry. If the user does not set this property, then read as false.- Parameters:
alwaysCacheBaseImage
- iftrue
, base image layers are always pulled and cached. Iffalse
, base image layers will not be pulled/cached if they already exist on the target registry.- Returns:
- this
-
addRegistryMirrors
public Containerizer addRegistryMirrors(java.lang.String registry, java.util.List<java.lang.String> mirrors)
Adds mirrors for a base image registry. Jib will try its mirrors in the given order before finally trying the registry.- Parameters:
registry
- base image registry for which mirrors are configuredmirrors
- a list of mirrors, where each element is in the form ofhost[:port]
- Returns:
- this
-
-