Skip to content

Commit

Permalink
Improve logging in native image builder
Browse files Browse the repository at this point in the history
  • Loading branch information
zakkak committed Feb 24, 2021
1 parent 5d4f39d commit ea2159f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
import java.nio.file.Path;
import java.util.List;

import org.jboss.logging.Logger;

import io.quarkus.deployment.pkg.NativeConfig;

public class NativeImageBuildRemoteContainerRunner extends NativeImageBuildContainerRunner {

private static final Logger log = Logger.getLogger(NativeImageBuildRemoteContainerRunner.class);

private final String nativeImageName;
private String containerId;

Expand All @@ -22,13 +26,15 @@ public NativeImageBuildRemoteContainerRunner(NativeConfig nativeConfig, Path out
protected void preBuild(List<String> buildArgs) throws InterruptedException, IOException {
List<String> containerRuntimeArgs = getContainerRuntimeBuildArgs();
String[] createContainerCommand = buildCommand("create", containerRuntimeArgs, buildArgs);
log.info(String.join(" ", createContainerCommand).replace("$", "\\$"));
Process createContainerProcess = new ProcessBuilder(createContainerCommand).start();
createContainerProcess.waitFor();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(createContainerProcess.getInputStream()))) {
containerId = reader.readLine();
}
String[] copyCommand = new String[] { containerRuntime.getExecutableName(), "cp", outputPath + "/.",
containerId + ":" + NativeImageBuildStep.CONTAINER_BUILD_VOLUME_PATH };
log.info(String.join(" ", copyCommand).replace("$", "\\$"));
Process copyProcess = new ProcessBuilder(copyCommand).start();
copyProcess.waitFor();
super.preBuild(buildArgs);
Expand All @@ -47,13 +53,15 @@ protected void postBuild() throws InterruptedException, IOException {
}
String[] removeCommand = new String[] { containerRuntime.getExecutableName(), "container", "rm", "--volumes",
containerId };
log.info(String.join(" ", removeCommand).replace("$", "\\$"));
Process removeProcess = new ProcessBuilder(removeCommand).start();
removeProcess.waitFor();
}

private void copy(String path) throws IOException, InterruptedException {
String[] copyCommand = new String[] { containerRuntime.getExecutableName(), "cp",
containerId + ":" + NativeImageBuildStep.CONTAINER_BUILD_VOLUME_PATH + "/" + path, outputPath };
log.info(String.join(" ", copyCommand).replace("$", "\\$"));
Process copyProcess = new ProcessBuilder(copyCommand).start();
copyProcess.waitFor();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.jboss.logging.Logger;

import io.quarkus.deployment.pkg.steps.NativeImageBuildStep.GraalVM;
import io.quarkus.deployment.util.ProcessUtil;

public abstract class NativeImageBuildRunner {

private static final Logger log = Logger.getLogger(NativeImageBuildRunner.class);

public GraalVM.Version getGraalVMVersion() {
final GraalVM.Version graalVMVersion;
try {
Expand Down Expand Up @@ -46,8 +50,10 @@ public int build(List<String> args, Path outputDir, boolean processInheritIODisa
preBuild(args);
try {
CountDownLatch errorReportLatch = new CountDownLatch(1);
final ProcessBuilder processBuilder = new ProcessBuilder(getBuildCommand(args))
final String[] buildCommand = getBuildCommand(args);
final ProcessBuilder processBuilder = new ProcessBuilder(buildCommand)
.directory(outputDir.toFile());
log.info(String.join(" ", buildCommand).replace("$", "\\$"));
final Process process = ProcessUtil.launchProcessStreamStdOut(processBuilder, processInheritIODisabled);
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.submit(new ErrorReplacingProcessReader(process.getErrorStream(), outputDir.resolve("reports").toFile(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ public NativeImageBuildItem build(NativeConfig nativeConfig, NativeImageSourceJa

List<String> nativeImageArgs = commandAndExecutable.args;

log.info(String.join(" ", nativeImageArgs).replace("$", "\\$"));
int exitCode = buildRunner.build(nativeImageArgs, outputDir, processInheritIODisabled.isPresent());
if (exitCode != 0) {
throw imageGenerationFailed(exitCode, nativeImageArgs);
Expand Down

0 comments on commit ea2159f

Please sign in to comment.