-
-
Notifications
You must be signed in to change notification settings - Fork 365
Making buildx optional #3851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Making buildx optional #3851
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,22 @@ ext { | |
| dockerPath = buildDir.absolutePath + "/docker" | ||
| } | ||
|
|
||
| // `--cache-from type=registry,...` is BuildKit syntax. The legacy builder parses it as an | ||
| // image reference and fails the build, so the flag may only be passed when buildx is installed. | ||
| def buildxProbeResult = null | ||
| def buildxAvailable = { | ||
| if (buildxProbeResult == null) { | ||
| try { | ||
| def proc = ["docker", "buildx", "version"].execute() | ||
| proc.consumeProcessOutput(new StringBuilder(), new StringBuilder()) | ||
| buildxProbeResult = proc.waitFor() == 0 | ||
| } catch (Exception ignored) { | ||
| buildxProbeResult = false | ||
| } | ||
| } | ||
| return buildxProbeResult | ||
|
Comment on lines
+7
to
+18
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- gradle/docker.gradle ---'
cat -n gradle/docker.gradle
printf '%s\n' '--- related Docker/BuildKit configuration ---'
rg -n -S --hidden 'DOCKER_BUILDKIT|buildx|cache-from|cache-to|docker build|windows-container|BUILDKIT' . \
-g '!node_modules' -g '!build' -g '!dist' || trueRepository: tolgee/tolgee-platform Length of output: 7296 🌐 Web query:
💡 Result: The legacy builder and BuildKit have significant functional differences, particularly regarding how they handle build cache and Windows container support. Compatibility with --cache-from The --cache-from type=registry syntax is a feature of BuildKit [1][2]. The legacy builder (invoked by setting DOCKER_BUILDKIT=0) does not support this specific cache backend syntax [3][4]. The legacy builder uses a different, implicit caching mechanism based on existing local image layers and does not support importing or exporting cache manifests or specialized OCI-formatted cache images from a registry [5][4]. Builder Selection and Windows Containers By default, Docker uses the BuildKit engine for Linux containers [4]. However, the legacy builder is still the default for Windows container mode due to historical lack of feature parity in BuildKit [3][4]. - Windows Container Support: While BuildKit has introduced experimental support for Windows containers (starting with v0.13.0), it is not yet the default [4][6]. Users who require BuildKit features on Windows must manually configure a separate BuildKit instance and use the docker buildx command to point to it [6]. - DOCKER_BUILDKIT=0: This environment variable explicitly disables BuildKit and forces the use of the legacy builder for the docker build command [3][7]. Using this variable is deprecated and generally discouraged, as the legacy builder lacks modern features such as concurrent build graph execution, advanced caching backends, and efficient multi-stage build handling [5][4][8]. - Selection Logic: The docker build command defaults to the legacy builder when Windows container mode is active or when DOCKER_BUILDKIT=0 is set [3][4]. Conversely, docker buildx build is designed to use BuildKit by default, regardless of the platform, and is the recommended approach for modern build workflows, even when using custom builder instances [2][9]. For reliable and modern build performance—including support for --cache-from type=registry—it is recommended to use the docker buildx build command with a properly configured BuildKit backend [1][9]. Projects relying on DOCKER_BUILDKIT=0 may experience performance limitations and issues with cache handling, particularly in cross-architecture or complex build scenarios [8]. Citations:
Gate the registry cache on the effective builder.
🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| tasks.register('dockerPrepare') { | ||
| doLast { | ||
| delete(dockerPath) | ||
|
|
@@ -23,10 +39,19 @@ tasks.register('dockerPrepare') { | |
| tasks.register('docker', Exec) { | ||
| dependsOn("dockerPrepare") | ||
| workingDir dockerPath | ||
| commandLine "docker", "build", ".", | ||
| "-t", "tolgee/tolgee", | ||
| "--build-arg", "OTEL_AGENT_VERSION=${opentelemetryJavaagentVersion}", | ||
| "--cache-from", "type=registry,ref=tolgee/tolgee:latest" | ||
| doFirst { | ||
| def params = ["docker", "build", ".", | ||
| "-t", "tolgee/tolgee", | ||
| "--build-arg", "OTEL_AGENT_VERSION=${opentelemetryJavaagentVersion}"] | ||
|
|
||
| if (buildxAvailable()) { | ||
| params += ["--cache-from", "type=registry,ref=tolgee/tolgee:latest"] | ||
| } else { | ||
| logger.lifecycle("docker buildx not found, building without the registry cache") | ||
| } | ||
|
|
||
| commandLine params | ||
| } | ||
| } | ||
|
|
||
| // Builds the slim Docker image, tagged as tolgee/tolgee:slim. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: tolgee/tolgee-platform
Length of output: 50379
🏁 Script executed:
Repository: tolgee/tolgee-platform
Length of output: 9345
🏁 Script executed:
Repository: tolgee/tolgee-platform
Length of output: 562
🌐 Web query:
Oracle Java Process.waitFor InterruptedException documentation Process.destroy Gradle consumeProcessOutput documentation💡 Result:
In Java and Gradle process management, here is the documentation regarding the requested methods: Java Process.waitFor and InterruptedException The java.lang.Process.waitFor method causes the current thread to block until the process represented by the Process object has terminated [1][2][3]. Because it is a blocking operation, it throws an InterruptedException if the current thread is interrupted by another thread while it is waiting [1][4]. When this exception is thrown, the wait is immediately ended [1][2]. The same behavior applies to the overloaded waitFor(long timeout, TimeUnit unit) method, which also throws an InterruptedException if the thread is interrupted before the timeout elapses or the process exits [1][4]. Java Process.destroy The java.lang.Process.destroy method kills the process [5]. Whether this termination is graceful or forced is implementation-dependent, though it is generally intended to allow for normal termination if possible [5]. For cases requiring immediate termination, the destroyForcibly method (available since Java 1.8) is used to forcibly terminate the process regardless of its state [5]. Gradle consumeProcessOutput The method consumeProcessOutput(OutputStream output, OutputStream error) is a Groovy-specific enhancement provided by Gradle to simplify the capture of a process's output [6]. It is not a standard Java API method but is added to Process objects when executed within a Gradle environment (e.g., inside an exec task or block) [6]. This method redirects the standard output and standard error streams of the process to the specified OutputStreams, which are typically closed automatically after the process completes [7][6]. In modern Gradle, users are encouraged to use the ProviderFactory#exec API for more robust, lazy-configured handling of process output [8]. Top Results: [1], [5], [7], [8]
Citations:
🏁 Script executed:
Repository: tolgee/tolgee-platform
Length of output: 539
Preserve interruption during the Buildx probe.
Handle
InterruptedExceptionseparately. Destroyproc, restore the interrupt status, and rethrow it. Keep generic failures as unavailable, but change the message from"docker buildx not found"because a nonzero exit or other exception does not prove that Buildx is missing.🤖 Prompt for AI Agents