This is an automated email from the ASF dual-hosted git repository.
dongjoon-hyun pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/spark-kubernetes-operator.git
The following commit(s) were added to refs/heads/main by this push:
new 3fcd3c54 [SPARK-61594] Build the operator jar once on `$BUILDPLATFORM`
in multi-platform Docker builds
3fcd3c54 is described below
commit 3fcd3c541837ea0ff8effa36973ba353ef4a9b66
Author: Dongjoon Hyun <[email protected]>
AuthorDate: Fri Nov 13 01:02:46 2026 -0800
[SPARK-61594] Build the operator jar once on `$BUILDPLATFORM` in
multi-platform Docker builds
### What changes were proposed in this pull request?
This PR aims to run the `builder` stage of `build-tools/docker/Dockerfile`
on `$BUILDPLATFORM`.
```diff
-FROM gradle:9.9.1-jdk27-resolute AS builder
+FROM --platform=$BUILDPLATFORM gradle:9.9.1-jdk27-resolute AS builder
```
A multi-platform build now runs Gradle once and copies the same jar into
every target platform image. The `jlink` and final stages still run per target
platform, so each image keeps its own custom JRE.
### Why are the changes needed?
Currently, `docker buildx build --platform linux/amd64,linux/arm64` runs
one `builder` stage per target platform, and both Gradle processes use the same
BuildKit cache mount, `/home/gradle/.gradle/caches`, at the same time.
When a Gradle process needs a lock that another process holds, it asks the
owner to release it over the loopback interface. With the `docker` driver (the
BuildKit built into Docker Engine), each `RUN` container has its own network
namespace, so the request never reaches the owner. The waiting build fails if
the other Gradle process still holds the lock 60 seconds later. For example, a
`linux/amd64,linux/arm64` build of `branch-1.1` on Rancher Desktop (Docker
Engine 29.9.2, BuildKit v0 [...]
```
> [linux/amd64 builder 4/4] RUN
--mount=type=cache,target=/home/gradle/.gradle/caches gradle --no-daemon clean
build -x check:
...
72.18 > Timeout waiting to lock journal cache
(/home/gradle/.gradle/caches/journal-1). It is currently in use by another
process.
72.18 Owner PID: 52
72.18 Our PID: 76
72.18 Owner Operation:
72.18 Our operation:
72.18 Lock file:
/home/gradle/.gradle/caches/journal-1/journal-1.lock
```
The `Publish Snapshot Image` workflow uses the `docker-container` driver
and has not failed. However, it builds the same jar twice, and the
`linux/arm64` build runs under QEMU. In the [run on
2026-11-12](https://github.com/apache/spark-kubernetes-operator/actions/runs/43126089808):
| `builder 4/4` | Duration |
| - | - |
| `linux/amd64` | 208s |
| `linux/arm64` (QEMU) | 914s |
The jar does not depend on the CPU architecture. Building it once on the
build platform removes the concurrent access and skips the emulated Gradle
build.
### Does this PR introduce _any_ user-facing change?
No. Only the way the image is built changes. Single-platform builds such as
`./gradlew buildDockerImage` and the E2E CI work as before because
`BUILDPLATFORM` is the same as `TARGETPLATFORM` there.
### How was this patch tested?
Manually on Rancher Desktop (Apple Silicon, `docker` driver, containerd
image store).
```
$ docker buildx build --platform linux/amd64,linux/arm64 --no-cache --load \
-t spark-kubernetes-operator:test -f build-tools/docker/Dockerfile .
```
- Before: the build of `branch-1.1` failed twice with the error above. The
failure depends on timing. On `main` with a warm cache, a multi-platform build
passed because the `linux/arm64` Gradle build finished in 74s. The
`linux/amd64` Gradle build under emulation took 290s.
- After: passed in 222s. Gradle ran once as `[linux/arm64 builder 4/4]`
(88s), and `jlink` ran per platform (`linux/arm64` 24s, `linux/amd64` 116s
under emulation).
Both images run their own JRE and contain the identical jar.
The cause was also confirmed with `gradle:9.9.1-jdk27-resolute` containers
that share a cache volume while one of them holds the lock. A Gradle process in
its own network namespace failed after 63 seconds with the same `journal-1`
error. A Gradle process started with `--network container:<owner>` got the lock
in 2 seconds.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 5.5
Closes #997 from dongjoon-hyun/SPARK-61594.
Authored-by: Dongjoon Hyun <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
---
build-tools/docker/Dockerfile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/build-tools/docker/Dockerfile b/build-tools/docker/Dockerfile
index a9e6fa38..763dc741 100644
--- a/build-tools/docker/Dockerfile
+++ b/build-tools/docker/Dockerfile
@@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-FROM gradle:9.9.1-jdk27-resolute AS builder
+FROM --platform=$BUILDPLATFORM gradle:9.9.1-jdk27-resolute AS builder
WORKDIR /app
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]