# HG changeset patch # User cin # Date 2024-02-18 21:33:35 # Node ID 452b9915903c0a8a10487f735c3759810564be3e # Parent bda3064b1cec418cad452d8225f38ed164382b2d Fixed docker build output handling. Handled with 'info' log level. diff --git a/container/gradle.properties b/container/gradle.properties --- a/container/gradle.properties +++ b/container/gradle.properties @@ -1,2 +1,2 @@ group=org.implab.gradle -version=1.3.0 \ No newline at end of file +version=1.3.1 \ No newline at end of file diff --git a/container/src/main/java/org/implab/gradle/containers/cli/ProcessSpec.java b/container/src/main/java/org/implab/gradle/containers/cli/ProcessSpec.java --- a/container/src/main/java/org/implab/gradle/containers/cli/ProcessSpec.java +++ b/container/src/main/java/org/implab/gradle/containers/cli/ProcessSpec.java @@ -2,6 +2,7 @@ package org.implab.gradle.containers.cli import java.io.File; import java.io.IOException; +import java.lang.ProcessBuilder.Redirect; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -31,6 +32,15 @@ public class ProcessSpec { builder.command(this.command); builder.directory(directory); + // discard stdout if not redirected + if (outputRedirect == null) + builder.redirectOutput(Redirect.DISCARD); + + // discard stderr if not redirected + if (errorRedirect == null) + builder.redirectError(Redirect.DISCARD); + + // run process var proc = builder.start(); tasks.add(proc.onExit()); diff --git a/container/src/main/java/org/implab/gradle/containers/cli/Utils.java b/container/src/main/java/org/implab/gradle/containers/cli/Utils.java --- a/container/src/main/java/org/implab/gradle/containers/cli/Utils.java +++ b/container/src/main/java/org/implab/gradle/containers/cli/Utils.java @@ -19,7 +19,6 @@ import java.nio.file.Files; import java.util.List; import org.gradle.api.Action; import org.gradle.api.GradleException; -import org.gradle.api.file.Directory; import org.gradle.api.file.FileSystemLocation; import org.gradle.internal.impldep.org.bouncycastle.util.Iterable; diff --git a/container/src/main/java/org/implab/gradle/containers/tasks/BuildImage.java b/container/src/main/java/org/implab/gradle/containers/tasks/BuildImage.java --- a/container/src/main/java/org/implab/gradle/containers/tasks/BuildImage.java +++ b/container/src/main/java/org/implab/gradle/containers/tasks/BuildImage.java @@ -24,6 +24,7 @@ import java.io.File; import java.io.IOException; import org.implab.gradle.containers.cli.ImageRef; +import org.implab.gradle.containers.cli.RedirectTo; import org.implab.gradle.containers.cli.Utils; import org.implab.gradle.containers.dsl.MapPropertyEntry; import org.implab.gradle.containers.dsl.OptionsMixin; @@ -91,6 +92,12 @@ public abstract class BuildImage extends } } + @Override + protected java.util.Optional loggerErrorRedirect() { + // https://github.com/moby/buildkit/issues/1186 + return loggerInfoRedirect(); + } + @TaskAction public void run() throws Exception { List args = new ArrayList<>(); diff --git a/container/src/main/java/org/implab/gradle/containers/tasks/DockerCliTask.java b/container/src/main/java/org/implab/gradle/containers/tasks/DockerCliTask.java --- a/container/src/main/java/org/implab/gradle/containers/tasks/DockerCliTask.java +++ b/container/src/main/java/org/implab/gradle/containers/tasks/DockerCliTask.java @@ -43,11 +43,15 @@ public abstract class DockerCliTask exte } protected Optional loggerInfoRedirect() { - return getLogger().isInfoEnabled() ? Optional.of(RedirectTo.consumer(getLogger()::info)) : Optional.empty(); + return getLogger().isInfoEnabled() ? + Optional.of(RedirectTo.consumer(getLogger()::info)) : + Optional.empty(); } protected Optional loggerErrorRedirect() { - return getLogger().isErrorEnabled() ? Optional.of(RedirectTo.consumer(getLogger()::error)) : Optional.empty(); + return getLogger().isErrorEnabled() ? + Optional.of(RedirectTo.consumer(getLogger()::error)) : + Optional.empty(); } protected Optional stdoutRedirection() { @@ -85,7 +89,6 @@ public abstract class DockerCliTask exte } protected void exec(ProcessSpec spec) throws InterruptedException, ExecutionException, IOException { - stdoutRedirection().ifPresent(spec::redirectStdout); stderrRedirection().ifPresent(spec::redirectStderr); stdinRedirection().ifPresent(spec::redirectStdin);