Repository navigation
Integrate Jib Docker builder into contrib/docker - #6815
Conversation
00fed52 to
4282542
Compare
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>
4282542 to
34dab7b
Compare
There was a problem hiding this comment.
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-coredependency wiring for the contrib docker module. - Refactors
DockerModuleconfigs into sharedBaseDockerConfig, defaultDockerConfig(Jib), andClassicDockerConfig(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.
| 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") | ||
| } |
There was a problem hiding this comment.
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.
| val ports: Set[Port] = | ||
| exposedPorts.map(Port.tcp).toSet ++ exposedUdpPorts.map(Port.udp).toSet | ||
| containerBuilder.setExposedPorts(ports.asJava) | ||
| containerBuilder.setCreationTime(java.time.Instant.now()) | ||
|
|
There was a problem hiding this comment.
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.
| ): JibContainer = { | ||
| val containerizer = targetImage match { | ||
| case JibImage.DockerDaemonImage(qualifiedName, _) => | ||
| Containerizer.to(DockerDaemonImage.named(qualifiedName)) |
There was a problem hiding this comment.
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.
| Containerizer.to(DockerDaemonImage.named(qualifiedName)) | |
| Containerizer.to(DockerDaemonImage.named(ImageReference.parse(qualifiedName))) |
| 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`. |
There was a problem hiding this comment.
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.
| 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`. |
|
|
||
| /** The target image for Jib. Defaults to a DockerDaemonImage using the first tag. */ | ||
| def jibTargetImage: T[JibTargetImage] = Task { | ||
| JibImage.DockerDaemonImage(tags().head): JibTargetImage |
There was a problem hiding this comment.
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.
| 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 |
| 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))) | ||
| } |
There was a problem hiding this comment.
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.
|
Is this derived from https://github.com/GeorgOfenbeck/mill-docker ? Does the code in this PR work well with multi-module projects? |
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: