public class JibContainerBuilder extends Object
Example usage:
Jib.from(baseImage)
.addLayer(sourceFiles, extractionPath)
.setEntrypoint("myprogram", "--flag", "subcommand")
.setProgramArguments("hello", "world")
.addEnvironmentVariable("HOME", "/app")
.addExposedPort(Port.tcp(8080))
.addLabel("containerizer", "jib")
.containerize(...);
| Modifier and Type | Method and Description |
|---|---|
JibContainerBuilder |
addEnvironmentVariable(String name,
String value)
Sets a variable in the container environment.
|
JibContainerBuilder |
addExposedPort(Port port)
Adds a port to expose from the container.
|
JibContainerBuilder |
addLabel(String key,
String value)
Sets a label for the container.
|
JibContainerBuilder |
addLayer(LayerConfiguration layerConfiguration)
Adds a layer (defined by a
LayerConfiguration). |
JibContainerBuilder |
addLayer(List<Path> files,
AbsoluteUnixPath pathInContainer)
Adds a new layer to the container with
files as the source files and pathInContainer as the path to copy the source files to in the container file system. |
JibContainerBuilder |
addLayer(List<Path> files,
String pathInContainer)
Adds a new layer to the container with
files as the source files and pathInContainer as the path to copy the source files to in the container file system. |
JibContainerBuilder |
addVolume(AbsoluteUnixPath volume)
Adds a directory that may hold an externally mounted volume.
|
JibContainer |
containerize(Containerizer containerizer)
Builds the container.
|
JibContainerBuilder |
setCreationTime(Instant creationTime)
Sets the container image creation time.
|
JibContainerBuilder |
setEntrypoint(List<String> entrypoint)
Sets the container entrypoint.
|
JibContainerBuilder |
setEntrypoint(String... entrypoint)
Sets the container entrypoint.
|
JibContainerBuilder |
setEnvironment(Map<String,String> environmentMap)
Sets the container environment.
|
JibContainerBuilder |
setExposedPorts(Port... ports)
Sets the ports to expose from the container.
|
JibContainerBuilder |
setExposedPorts(Set<Port> ports)
Sets the ports to expose from the container.
|
JibContainerBuilder |
setFormat(ImageFormat imageFormat)
Sets the format to build the container image as.
|
JibContainerBuilder |
setLabels(Map<String,String> labelMap)
Sets the labels for the container.
|
JibContainerBuilder |
setLayers(LayerConfiguration... layerConfigurations)
Sets the layers.
|
JibContainerBuilder |
setLayers(List<LayerConfiguration> layerConfigurations)
Sets the layers (defined by a list of
LayerConfigurations). |
JibContainerBuilder |
setProgramArguments(List<String> programArguments)
Sets the container entrypoint program arguments.
|
JibContainerBuilder |
setProgramArguments(String... programArguments)
Sets the container entrypoint program arguments.
|
JibContainerBuilder |
setUser(String user)
Sets the user and group to run the container as.
|
JibContainerBuilder |
setVolumes(AbsoluteUnixPath... volumes)
Sets the directories that may hold externally mounted volumes.
|
JibContainerBuilder |
setVolumes(Set<AbsoluteUnixPath> volumes)
Sets the directories that may hold externally mounted volumes.
|
JibContainerBuilder |
setWorkingDirectory(AbsoluteUnixPath workingDirectory)
Sets the working directory in the container.
|
public JibContainerBuilder addLayer(List<Path> files, AbsoluteUnixPath pathInContainer) throws IOException
files as the source files and pathInContainer as the path to copy the source files to in the container file system.
Source files that are directories will be recursively copied. For example, if the source files are:
fileA
fileB
directory/
/path/in/container, then the new layer will have the
following entries for the container file system:
/path/in/container/fileA
/path/in/container/fileB
/path/in/container/directory/
/path/in/container/directory/... (all contents of directory/)
files - the source files to copy to a new layer in the containerpathInContainer - the path in the container file system corresponding to the sourceFileIOException - if an exception occurred when recursively listing any directoriespublic JibContainerBuilder addLayer(List<Path> files, String pathInContainer) throws IOException
files as the source files and pathInContainer as the path to copy the source files to in the container file system.files - the source files to copy to a new layer in the containerpathInContainer - the path in the container file system corresponding to the sourceFileIOException - if an exception occurred when recursively listing any directoriesIllegalArgumentException - if pathInContainer is not an absolute Unix-style pathaddLayer(List, AbsoluteUnixPath)public JibContainerBuilder addLayer(LayerConfiguration layerConfiguration)
LayerConfiguration).layerConfiguration - the LayerConfigurationpublic JibContainerBuilder setLayers(List<LayerConfiguration> layerConfigurations)
LayerConfigurations). This replaces any
previously-added layers.layerConfigurations - the list of LayerConfigurationspublic JibContainerBuilder setLayers(LayerConfiguration... layerConfigurations)
layerConfigurations - the LayerConfigurationspublic JibContainerBuilder setEntrypoint(@Nullable List<String> entrypoint)
setProgramArguments(java.util.List<java.lang.String>) sets additional tokens.
This is similar to ENTRYPOINT in Dockerfiles or command in the Kubernetes
Container spec.
entrypoint - a list of the entrypoint commandpublic JibContainerBuilder setEntrypoint(String... entrypoint)
entrypoint - the entrypoint commandsetEntrypoint(List)public JibContainerBuilder setProgramArguments(@Nullable List<String> programArguments)
This is similar to CMD in Dockerfiles or args in the Kubernetes
Container spec.
For example, if the entrypoint was myprogram --flag subcommand and program arguments
were hello world, then the command that run when the container starts is myprogram --flag subcommand hello world.
programArguments - a list of program argument tokenspublic JibContainerBuilder setProgramArguments(String... programArguments)
programArguments - program arguments tokenssetProgramArguments(List)public JibContainerBuilder setEnvironment(Map<String,String> environmentMap)
This is similar to ENV in Dockerfiles or env in the Kubernetes
Container spec.
environmentMap - a map of environment variable names to valuespublic JibContainerBuilder addEnvironmentVariable(String name, String value)
name - the environment variable namevalue - the environment variable valuesetEnvironment(java.util.Map<java.lang.String, java.lang.String>)public JibContainerBuilder setVolumes(Set<AbsoluteUnixPath> volumes)
This is similar to VOLUME in Dockerfiles.
volumes - the directory paths on the container filesystem to set as volumespublic JibContainerBuilder setVolumes(AbsoluteUnixPath... volumes)
volumes - the directory paths on the container filesystem to set as volumessetVolumes(Set)public JibContainerBuilder addVolume(AbsoluteUnixPath volume)
volume - a directory path on the container filesystem to represent a volumesetVolumes(Set)public JibContainerBuilder setExposedPorts(Set<Port> ports)
Use Port.tcp(int) to expose a port for TCP traffic and Port.udp(int) to expose a port
for UDP traffic.
This is similar to EXPOSE in Dockerfiles or ports in the Kubernetes
Container spec.
ports - the ports to exposepublic JibContainerBuilder setExposedPorts(Port... ports)
ports - the ports to exposesetExposedPorts(Set)public JibContainerBuilder addExposedPort(Port port)
port - the port to exposesetExposedPorts(Set)public JibContainerBuilder setLabels(Map<String,String> labelMap)
This is similar to LABEL in Dockerfiles.
labelMap - a map of label keys to valuespublic JibContainerBuilder addLabel(String key, String value)
key - the label keyvalue - the label valuepublic JibContainerBuilder setFormat(ImageFormat imageFormat)
ImageFormat.Docker for Docker V2.2
or ImageFormat.OCI for OCI.imageFormat - the ImageFormatpublic JibContainerBuilder setCreationTime(Instant creationTime)
Instant.EPOCH.creationTime - the container image creation timepublic JibContainerBuilder setUser(@Nullable String user)
user can be a username or UID along
with an optional groupname or GID.
The following are valid formats for user
user
uid
user:group
uid:gid
uid:group
user:gid
user - the user to run the container aspublic JibContainerBuilder setWorkingDirectory(@Nullable AbsoluteUnixPath workingDirectory)
workingDirectory - the working directorypublic JibContainer containerize(Containerizer containerizer) throws InterruptedException, RegistryException, IOException, CacheDirectoryCreationException, ExecutionException
containerizer - the Containerizer that configures how to containerizeIOException - if an I/O exception occursCacheDirectoryCreationException - if a directory to be used for the cache could not be
createdorg.apache.http.conn.HttpHostConnectException - if jib failed to connect to a registryRegistryUnauthorizedException - if a registry request is unauthorized and needs
authenticationRegistryAuthenticationFailedException - if registry authentication failedUnknownHostException - if the registry does not existInsecureRegistryException - if a server could not be verified due to an insecure
connectionRegistryException - if some other error occurred while interacting with a registryExecutionException - if some other exception occurred during executionInterruptedException - if the execution was interruptedCopyright © 2019. All rights reserved.