jib-core/README.md
Jib Core is a Java library for building Docker and OCI container images. It implements a general-purpose container builder that can be used to build containers without a Docker daemon, for any application. The implementation is pure Java.
The API is currently in beta and may change substantially.
Jib Core powers the popular Jib plugins for Maven and Gradle. The plugins build containers specifically for JVM languages and separate the application into multiple layers to optimize for fast rebuilds.
For the Maven plugin, see the jib-maven-plugin project.
For the Gradle plugin, see the jib-gradle-plugin project.
For information about the Jib project, see the Jib project README.
Add Jib Core as a dependency using Maven:
<dependency>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-core</artifactId>
<version>0.28.1</version>
</dependency>
Add Jib Core as a dependency using Gradle:
dependencies {
compile 'com.google.cloud.tools:jib-core:0.28.1'
}
Jib.from("busybox")
.addLayer(Arrays.asList(Paths.get("helloworld.sh")), AbsoluteUnixPath.get("/"))
.setEntrypoint("sh", "/helloworld.sh")
.containerize(
Containerizer.to(RegistryImage.named("gcr.io/my-project/hello-from-jib")
.addCredential("myusername", "mypassword")));
Jib.from("busybox") creates a new JibContainerBuilder configured with busybox as the base image..addLayer(...) configures the JibContainerBuilder with a new layer with helloworld.sh (local file) to be placed into the container at /helloworld.sh..setEntrypoint("sh", "/helloworld.sh") sets the entrypoint of the container to run /helloworld.sh.RegistryImage.named("gcr.io/my-project/hello-from-jib") creates a new RegistryImage configured with gcr.io/my-project/hello-from-jib as the target image to push to..addCredential adds the username/password credentials to authenticate the push to gcr.io/my-project/hello-from-jib. See CredentialRetrieverFactory for common credential retrievers (to retrieve credentials from Docker config or credential helpers, for example). These credential retrievers can be used with .addCredentialRetriever.Containerizer.to creates a new Containerizer configured to push to the RegistryImage..containerize executes the containerization. If successful, the container image will be available at gcr.io/my-project/hello-from-jib.See examples for links to more jib-core samples. We welcome contributions for additional examples and tutorials!
Jib - the main entrypoint for using Jib Core
JibContainerBuilder - configures the container to build
Containerizer - configures how and where to containerize to
JibContainer - information about the built container
Three types define what Jib can accept as either the base image or as the build target:
RegistryImage - an image on a container registryDockerDaemonImage - an image in the Docker daemonTarImage - an image saved as a tarball archive on the filesystemOther useful classes:
ImageReference - represents an image reference and has useful methods for parsing and manipulating image referencesLayerConfiguration - configures a container layer to buildCredentialRetriever - implement with custom credential retrieval methods for authenticating against a container registryCredentialRetrieverFactory - provides useful CredentialRetrievers to retrieve credentials from Docker config and credential helpersJava-specific API:
JavaContainerBuilder - configures a JibContainerBuilder for Java-specific applicationsMainClassFinder - find the main Java class in a given list of class filesThe Jib Core system consists 3 main parts:
Some other parts of Jib Core internals include:
Containerizer.setApplicationLayersCache and Containerizer.setBaseImageLayersCache)Containerizer.addEventHandler)Throughout the build process, Jib Core dispatches events that provide useful information. These events implement the type JibEvent, and can be handled by registering event handlers with the containerizer.
Jib.from(...)
...
.containerize(
Containerizer.to(...)
...
.addEventHandler(LogEvent.class, logEvent -> System.out.println(logEvent.getLevel() + ": " + logEvent.getMessage())
.addEventHandler(TimerEvent.class, timeEvent -> ...));
When Jib dispatches events, the event handlers you defined for that event type will be called. The following are the types of events you can listen for in Jib core (see API reference for more information):
LogEvent - Log message events. The message and verbosity can be retrieved using getMessage() and getLevel(), respectively.TimerEvent (Incubating) - Events used for measuring how long different build steps take. You can retrieve the duration since the timer's creation and the duration since the same timer's previous event using getElapsed() and getDuration(), respectively.ProgressEvent (Incubating) - Indicates the amount of progress build steps have made. Each progress event consists of an allocation (containing a fraction representing how much of the root allocation this allocation accounts for) and a number of progress units that indicates the amount of work completed since the previous progress event. In other words, the amount of work a single progress event has completed (out of 1.0) can be calculated using getAllocation().getFractionOfRoot() * getUnits().See the Jib project FAQ.
See Milestones for planned features. Get involved with the community for the latest updates.
See the Jib project README.