Skip to content

Integrate Jib Docker builder into contrib/docker - #6815

Merged
lihaoyi merged 1 commit into
com-lihaoyi:mainfrom
nightscape:contrib-docker-jib
Feb 12, 2026
Merged

lihaoyi merged 1 commit into
com-lihaoyi:mainfrom
nightscape:contrib-docker-jib

Conversation

@nightscape

@nightscape nightscape commented Feb 10, 2026 •

Copy link
Copy Markdown
Contributor

Add Jib (Google's container image builder) as the default Docker image build backend in contrib/docker. Jib builds images without requiring a Docker daemon or CLI, producing optimized layered images directly.

DockerConfig now uses Jib by default. The existing Dockerfile-based approach is available via ClassicDockerConfig for users who need Dockerfile features like RUN instructions and VOLUME mounts.

New files:

  • JibTypes.scala: Type definitions (JibImageFormat, JibSourceImage, etc.)
  • JibLogging.scala: Bridges Mill logger to Jib's event system
  • JibBuild.scala: Core Jib build logic (layers, container params, main class detection)

Add Jib (Google's container image builder) as the default Docker image
build backend in contrib/docker. Jib builds images without requiring a
Docker daemon or CLI, producing optimized layered images directly.

DockerConfig now uses Jib by default. The existing Dockerfile-based
approach is available via ClassicDockerConfig for users who need
Dockerfile features like RUN instructions and VOLUME mounts.

New files:
- JibTypes.scala: Type definitions (JibImageFormat, JibSourceImage, etc.)
- JibLogging.scala: Bridges Mill logger to Jib's event system
- JibBuild.scala: Core Jib build logic (layers, container params, main class detection)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@nightscape
nightscape marked this pull request as ready for review February 11, 2026 16:45
Copilot AI review requested due to automatic review settings February 11, 2026 16:45
@nightscape

Copy link
Copy Markdown
Contributor Author

@lihaoyi @lefou ready for a first review 👍

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR integrates Google’s Jib as the default image build backend for contrib/docker, while preserving the existing Dockerfile+CLI flow behind ClassicDockerConfig.

Changes:

  • Adds jib-core dependency wiring for the contrib docker module.
  • Refactors DockerModule configs into shared BaseDockerConfig, default DockerConfig (Jib), and ClassicDockerConfig (Dockerfile/CLI).
  • Introduces Jib implementation files (JibBuild, JibTypes, JibLogging) and expands the docker contrib test suite + documentation accordingly.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
mill-build/src/millbuild/Deps.scala Adds jib-core dependency definition.
contrib/package.mill Wires jib-core into the contrib docker module dependencies.
contrib/docker/src/mill/contrib/docker/DockerModule.scala Introduces Jib-backed default config and splits classic Dockerfile mode into ClassicDockerConfig.
contrib/docker/src/mill/contrib/docker/JibBuild.scala Implements core Jib build/containerize logic (layers, params, main class detection).
contrib/docker/src/mill/contrib/docker/JibTypes.scala Adds Jib-related ADTs and uPickle serializers for task caching/serialization.
contrib/docker/src/mill/contrib/docker/JibLogging.scala Bridges Mill logging to Jib event/log handlers.
contrib/docker/test/src/mill/contrib/docker/DockerModuleTest.scala Updates classic tests to use ClassicDockerConfig and adds Jib build tests.
contrib/docker/readme.adoc Updates docs to describe Jib default and classic Dockerfile option.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +187 to +203
def push() = Task.Command {
val log = Task.log
log.info("Pushing image with Jib")
val jibBuilder = getJibBuilder()

tags().foreach { tag =>
val registryImage = com.google.cloud.tools.jib.api.RegistryImage.named(
ImageReference.parse(tag)
)
val containerizer = Containerizer.to(registryImage)
.addEventHandler(JibLogging.logger(log))
.setAllowInsecureRegistries(allowInsecureRegistries())
.setToolName("mill-contrib-docker-jib")

jibBuilder.containerize(containerizer)
log.info(s"Pushed: $tag")
}

Copilot AI Feb 11, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

push() containerizes once per tag, which will rebuild and push the image multiple times. Jib supports pushing additional tags in a single containerization; consider pushing once to the first tag and adding the remaining tags as additional tags to avoid redundant work.

Copilot uses AI. Check for mistakes.
Comment on lines +90 to +94
val ports: Set[Port] =
exposedPorts.map(Port.tcp).toSet ++ exposedUdpPorts.map(Port.udp).toSet
containerBuilder.setExposedPorts(ports.asJava)
containerBuilder.setCreationTime(java.time.Instant.now())

Copilot AI Feb 11, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setCreationTime(Instant.now()) makes Jib builds non-reproducible and can reduce cache effectiveness because the image config changes every run. Unless there is a strong reason to stamp build time, consider using Jib's default (typically epoch) or a configurable creation time for deterministic builds.

Copilot uses AI. Check for mistakes.
): JibContainer = {
val containerizer = targetImage match {
case JibImage.DockerDaemonImage(qualifiedName, _) =>
Containerizer.to(DockerDaemonImage.named(qualifiedName))

Copilot AI Feb 11, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In containerize, the Docker daemon target uses DockerDaemonImage.named(qualifiedName) while javaBuild parses via ImageReference.parse(qualifiedName). Using ImageReference.parse here too would give consistent validation/handling of image references and clearer errors on invalid names.

Suggested change
Containerizer.to(DockerDaemonImage.named(qualifiedName))
Containerizer.to(DockerDaemonImage.named(ImageReference.parse(qualifiedName)))

Copilot uses AI. Check for mistakes.
Comment on lines +6 to +8
By default, images are built using https://github.com/GoogleContainerTools/jib[Jib],
which does not require a Docker daemon or CLI. To use the classic Dockerfile-based
approach, extend `ClassicDockerConfig` instead of `DockerConfig`.

Copilot AI Feb 11, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The README states Jib "does not require a Docker daemon or CLI", but the default jibTargetImage is a DockerDaemonImage, which still requires a local Docker-compatible daemon (even if not the CLI). Consider clarifying that Jib can build without a daemon when targeting a registry or tar output, or adjust the default target accordingly.

Suggested change
By default, images are built using https://github.com/GoogleContainerTools/jib[Jib],
which does not require a Docker daemon or CLI. To use the classic Dockerfile-based
approach, extend `ClassicDockerConfig` instead of `DockerConfig`.
By default, images are built using https://github.com/GoogleContainerTools/jib[Jib].
Jib itself can build images without a Docker daemon or CLI when configured to push
directly to a registry or to a tarball, but the default `DockerConfig` uses a
`DockerDaemonImage` target, which requires a local Docker-compatible daemon.
To build without a daemon, override `jibTargetImage` to use a registry or tar
output. To use the classic Dockerfile-based approach, extend `ClassicDockerConfig`
instead of `DockerConfig`.

Copilot uses AI. Check for mistakes.

/** The target image for Jib. Defaults to a DockerDaemonImage using the first tag. */
def jibTargetImage: T[JibTargetImage] = Task {
JibImage.DockerDaemonImage(tags().head): JibTargetImage

Copilot AI Feb 11, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jibTargetImage defaults to tags().head, which will throw if a user overrides tags to an empty list. Consider failing with a clearer message (or providing a safe default) when tags() is empty so the task errors are actionable.

Suggested change
JibImage.DockerDaemonImage(tags().head): JibTargetImage
val ts = tags()
val headTag = ts.headOption.getOrElse {
throw new IllegalArgumentException(
"Docker tags() is empty; JibDockerConfig requires at least one tag " +
"to derive jibTargetImage. Either define tags with at least one tag, " +
"or override jibTargetImage explicitly."
)
}
JibImage.DockerDaemonImage(headTag): JibTargetImage

Copilot uses AI. Check for mistakes.
Comment on lines +206 to +215
private def parsePlatform(platformStr: String): Set[JibPlatform] =
if (platformStr.isEmpty) Set.empty
else {
val parts = platformStr.split("/", 2)
assert(
parts.length == 2,
s"Platform must be in 'os/architecture' format, got: $platformStr"
)
Set(JibPlatform(os = parts(0), architecture = parts(1)))
}

Copilot AI Feb 11, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parsePlatform uses assert for validating user input. Scala assert can be elided by compiler settings, and even when enabled it throws AssertionError which is less user-friendly for task configuration errors. Prefer require/explicit validation that throws an IllegalArgumentException or uses Mill's task failure mechanism with the same message.

Copilot uses AI. Check for mistakes.
@lihaoyi
lihaoyi merged commit 7d79359 into com-lihaoyi:main Feb 12, 2026
50 of 51 checks passed
@lefou lefou added this to the 1.1.3 milestone Feb 12, 2026
@nightscape
nightscape deleted the contrib-docker-jib branch February 12, 2026 07:22
@sideeffffect

Copy link
Copy Markdown
Contributor

Is this derived from https://github.com/GeorgOfenbeck/mill-docker ?
There was a fatal issue(s?) with packaging a multi-module project to an image

Does the code in this PR work well with multi-module projects?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants