public class JibContainerBuilder
extends java.lang.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(java.lang.String name,
java.lang.String value)
Sets a variable in the container environment.
|
JibContainerBuilder |
addExposedPort(Port port)
Adds a port to expose from the container.
|
JibContainerBuilder |
addLabel(java.lang.String key,
java.lang.String value)
Sets a label for the container.
|
JibContainerBuilder |
addLayer(LayerConfiguration layerConfiguration)
Adds a layer (defined by a
LayerConfiguration ). |
JibContainerBuilder |
addLayer(java.util.List<java.nio.file.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. |
JibContainer |
containerize(Containerizer containerizer)
Builds the container(s).
|
JibContainerBuilder |
setCreationTime(java.time.Instant creationTime)
Sets the container image creation time.
|
JibContainerBuilder |
setEntrypoint(java.util.List<java.lang.String> entrypoint)
Sets the container entrypoint.
|
JibContainerBuilder |
setEntrypoint(java.lang.String... entrypoint)
Sets the container entrypoint.
|
JibContainerBuilder |
setEnvironment(java.util.Map<java.lang.String,java.lang.String> environmentMap)
Sets the container environment.
|
JibContainerBuilder |
setExposedPorts(java.util.List<Port> ports)
Sets the ports to expose from the container.
|
JibContainerBuilder |
setExposedPorts(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(java.util.Map<java.lang.String,java.lang.String> labelMap)
Sets the labels for the container.
|
JibContainerBuilder |
setLayers(LayerConfiguration... layerConfigurations)
Sets the layers.
|
JibContainerBuilder |
setLayers(java.util.List<LayerConfiguration> layerConfigurations)
Sets the layers (defined by a list of
LayerConfiguration s). |
JibContainerBuilder |
setProgramArguments(java.util.List<java.lang.String> programArguments)
Sets the container entrypoint program arguments.
|
JibContainerBuilder |
setProgramArguments(java.lang.String... programArguments)
Sets the container entrypoint program arguments.
|
JibContainerBuilder |
setUser(java.lang.String user)
Sets the user and group to run the container as.
|
public JibContainerBuilder addLayer(java.util.List<java.nio.file.Path> files, AbsoluteUnixPath pathInContainer) throws java.io.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 sourceFile
java.io.IOException
- if an exception occurred when recursively listing any directoriespublic JibContainerBuilder setLayers(java.util.List<LayerConfiguration> layerConfigurations)
LayerConfiguration
s). This replaces any
previously-added layers.layerConfigurations
- the list of LayerConfiguration
spublic JibContainerBuilder setLayers(LayerConfiguration... layerConfigurations)
layerConfigurations
- the LayerConfiguration
spublic JibContainerBuilder addLayer(LayerConfiguration layerConfiguration)
LayerConfiguration
).layerConfiguration
- the LayerConfiguration
public JibContainerBuilder setEntrypoint(java.util.List<java.lang.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(java.lang.String... entrypoint)
entrypoint
- the entrypoint commandfor more details
public JibContainerBuilder setProgramArguments(java.util.List<java.lang.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(java.lang.String... programArguments)
programArguments
- program arguments tokensfor more details
public JibContainerBuilder setEnvironment(java.util.Map<java.lang.String,java.lang.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(java.lang.String name, java.lang.String value)
name
- the environment variable namevalue
- the environment variable valuefor more details
public JibContainerBuilder setExposedPorts(java.util.List<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 list of ports to exposepublic JibContainerBuilder setExposedPorts(Port... ports)
ports
- the ports to exposefor more details
public JibContainerBuilder addExposedPort(Port port)
port
- the port to exposefor more details
public JibContainerBuilder setLabels(java.util.Map<java.lang.String,java.lang.String> labelMap)
This is similar to LABEL
in Dockerfiles.
labelMap
- a map of label keys to valuespublic JibContainerBuilder addLabel(java.lang.String key, java.lang.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 ImageFormat
public JibContainerBuilder setCreationTime(java.time.Instant creationTime)
Instant.EPOCH
.creationTime
- the container image creation timepublic JibContainerBuilder setUser(@Nullable java.lang.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 JibContainer containerize(Containerizer containerizer) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.io.IOException, CacheDirectoryCreationException
containerizer
- the Containerizer
that configures how to containerizeCacheDirectoryCreationException
- if a directory to be used for the cache could not be
createdjava.util.concurrent.ExecutionException
- if an exception occurred during executionjava.lang.InterruptedException
- if the execution was interruptedjava.io.IOException
- if an I/O exception occurs