Jib Build

Jib is a set of plugins for Maven and Gradle for building optimized OCI-compliant container images for Java applications without a Docker daemon.

Skaffold can help build artifacts using Jib; Jib builds the container images and then pushes them to the local Docker daemon or to remote registries as instructed by Skaffold.

Skaffold requires using Jib v1.4.0 or later.

Skaffold supports building with Jib

  1. locally and
  2. remotely on Google Cloud Build

Jib Maven and Gradle locally

Configuration

To use Jib, add a jib field to each artifact you specify in the artifacts part of the build section. context should be a path to your Maven or Gradle project.

The jib type offers the following options:

Option Description Default
project selects which sub-project to build for multi-module builds.
args additional build flags passed to the builder. []
type the Jib builder type; normally determined automatically. Valid types are maven: for Maven. gradle: for Gradle.

Skaffold’s jib support chooses the underlying builder (Maven or Gradle) based on the presence of standard build files in the artifact’s context directory:

  • Maven: pom.xml, or .mvn directory.
  • Gradle: build.gradle, gradle.properties, settings.gradle, or the Gradle wrapper script (gradlew, gradlew.bat, or gradlew.cmd).

Example

See the Skaffold-Jib demo project for an example.

Multi-Module Projects

Skaffold can be configured for multi-module projects too. A multi-module project has several modules (Maven terminology) or sub-projects (Gradle terminology) that each produce a separate container image.

Maven

To build a Maven multi-module project, first identify the sub-projects (also called modules in Maven) that should produce a container image. Then for each such sub-project:

  • Create a Skaffold artifact in the skaffold.yaml.
  • Set the artifact’s context field to the root project location.
  • Add a jib element and set its project field to the sub-project’s :artifactId, groupId:artifactId, or the relative path to the sub-project within the project.

Gradle

To build a multi-module project with Gradle, first identify the sub-projects that should produce a container image. Then for each such sub-project:

  • Create a Skaffold artifact in the skaffold.yaml.
  • Set the artifact’s context field to the root project location.
  • Add a jib element and set its project field to the sub-project’s name (the directory, by default).

Remotely with Google Cloud Build

Skaffold can build artifacts using Jib remotely on Google Cloud Build.

Configuration

To configure, add googleCloudBuild to build section to skaffold.yaml

Example

Following configuration instructs skaffold to build gcr.io/k8s-skaffold/project1 with Google Cloud Build using Jib builder:

build:
  artifacts:
  - image: gcr.io/k8s-skaffold/project1
    jib: {}
  googleCloudBuild:
    projectId: YOUR-GCP-PROJECT
Last modified November 6, 2019: code review changes (579d01a32)