diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/NativeConfig.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/NativeConfig.java index fe97f741a510b..ba04dd8393c19 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/NativeConfig.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/NativeConfig.java @@ -5,13 +5,13 @@ import java.util.Optional; import java.util.OptionalInt; -import io.quarkus.deployment.util.ContainerRuntimeUtil; import io.quarkus.runtime.annotations.ConfigGroup; import io.quarkus.runtime.annotations.ConfigItem; import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; import io.quarkus.runtime.annotations.ConvertWith; import io.quarkus.runtime.configuration.TrimmedStringConverter; +import io.quarkus.runtime.util.ContainerRuntimeUtil; @ConfigRoot(phase = ConfigPhase.BUILD_TIME) public class NativeConfig { diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildContainerRunner.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildContainerRunner.java index a612c8f307507..a3e8b127f65e2 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildContainerRunner.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildContainerRunner.java @@ -14,8 +14,8 @@ import org.jboss.logging.Logger; import io.quarkus.deployment.pkg.NativeConfig; -import io.quarkus.deployment.util.ContainerRuntimeUtil; import io.quarkus.deployment.util.ProcessUtil; +import io.quarkus.runtime.util.ContainerRuntimeUtil; public abstract class NativeImageBuildContainerRunner extends NativeImageBuildRunner { diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildLocalContainerRunner.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildLocalContainerRunner.java index 2f635a7a4b7c6..b63f2cb92886f 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildLocalContainerRunner.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildLocalContainerRunner.java @@ -11,8 +11,8 @@ import org.apache.commons.lang3.SystemUtils; import io.quarkus.deployment.pkg.NativeConfig; -import io.quarkus.deployment.util.ContainerRuntimeUtil; import io.quarkus.deployment.util.FileUtil; +import io.quarkus.runtime.util.ContainerRuntimeUtil; public class NativeImageBuildLocalContainerRunner extends NativeImageBuildContainerRunner { diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/UpxCompressionBuildStep.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/UpxCompressionBuildStep.java index e0df4c86b0d8d..2f12f6edf7be0 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/UpxCompressionBuildStep.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/UpxCompressionBuildStep.java @@ -20,9 +20,9 @@ import io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem; import io.quarkus.deployment.pkg.builditem.NativeImageBuildItem; import io.quarkus.deployment.pkg.builditem.UpxCompressedBuildItem; -import io.quarkus.deployment.util.ContainerRuntimeUtil; import io.quarkus.deployment.util.FileUtil; import io.quarkus.deployment.util.ProcessUtil; +import io.quarkus.runtime.util.ContainerRuntimeUtil; public class UpxCompressionBuildStep { diff --git a/core/deployment/src/main/java/io/quarkus/deployment/util/ContainerRuntimeUtil.java b/core/runtime/src/main/java/io/quarkus/runtime/util/ContainerRuntimeUtil.java similarity index 94% rename from core/deployment/src/main/java/io/quarkus/deployment/util/ContainerRuntimeUtil.java rename to core/runtime/src/main/java/io/quarkus/runtime/util/ContainerRuntimeUtil.java index d1e7fe6988462..b886e12ff980e 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/util/ContainerRuntimeUtil.java +++ b/core/runtime/src/main/java/io/quarkus/runtime/util/ContainerRuntimeUtil.java @@ -1,4 +1,4 @@ -package io.quarkus.deployment.util; +package io.quarkus.runtime.util; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -47,7 +47,7 @@ private static String getVersionOutputFor(ContainerRuntime containerRuntime) { .redirectErrorStream(true); versionProcess = pb.start(); versionProcess.waitFor(); - return new String(FileUtil.readFileContents(versionProcess.getInputStream()), StandardCharsets.UTF_8); + return new String(versionProcess.getInputStream().readAllBytes(), StandardCharsets.UTF_8); } catch (IOException | InterruptedException e) { // If an exception is thrown in the process, just return an empty String log.debugf(e, "Failure to read version output from %s", containerRuntime.getExecutableName()); diff --git a/extensions/container-image/container-image-jib/deployment/src/main/java/io/quarkus/container/image/jib/deployment/JibProcessor.java b/extensions/container-image/container-image-jib/deployment/src/main/java/io/quarkus/container/image/jib/deployment/JibProcessor.java index e4e18dd9ecc6b..367d118d9ceeb 100644 --- a/extensions/container-image/container-image-jib/deployment/src/main/java/io/quarkus/container/image/jib/deployment/JibProcessor.java +++ b/extensions/container-image/container-image-jib/deployment/src/main/java/io/quarkus/container/image/jib/deployment/JibProcessor.java @@ -72,9 +72,9 @@ import io.quarkus.deployment.pkg.builditem.UpxCompressedBuildItem; import io.quarkus.deployment.pkg.steps.JarResultBuildStep; import io.quarkus.deployment.pkg.steps.NativeBuild; -import io.quarkus.deployment.util.ContainerRuntimeUtil; import io.quarkus.fs.util.ZipUtils; import io.quarkus.maven.dependency.ResolvedDependency; +import io.quarkus.runtime.util.ContainerRuntimeUtil; public class JibProcessor { diff --git a/test-framework/common/src/main/java/io/quarkus/test/common/DefaultDockerContainerLauncher.java b/test-framework/common/src/main/java/io/quarkus/test/common/DefaultDockerContainerLauncher.java index 4e35e16a14bfd..f3c2d2c7e1412 100644 --- a/test-framework/common/src/main/java/io/quarkus/test/common/DefaultDockerContainerLauncher.java +++ b/test-framework/common/src/main/java/io/quarkus/test/common/DefaultDockerContainerLauncher.java @@ -20,12 +20,11 @@ import org.apache.commons.lang3.RandomStringUtils; +import io.quarkus.runtime.util.ContainerRuntimeUtil; import io.quarkus.test.common.http.TestHTTPResourceManager; public class DefaultDockerContainerLauncher implements DockerContainerArtifactLauncher { - private static final String DOCKER_BINARY = "docker"; - private int httpPort; private int httpsPort; private long waitTimeSeconds; @@ -42,6 +41,8 @@ public class DefaultDockerContainerLauncher implements DockerContainerArtifactLa private String containerName; + private String containerRuntimeBinaryName; + @Override public void init(DockerContainerArtifactLauncher.DockerInitContext initContext) { this.httpPort = initContext.httpPort(); @@ -63,11 +64,13 @@ public LaunchResult runToCompletion(String[] args) { @Override public void start() throws IOException { + containerRuntimeBinaryName = determineBinary(); + if (pullRequired) { System.out.println("Pulling container image '" + containerImage + "'"); try { int pullResult = new ProcessBuilder().redirectError(DISCARD).redirectOutput(DISCARD) - .command(DOCKER_BINARY, "pull", containerImage).start().waitFor(); + .command(containerRuntimeBinaryName, "pull", containerImage).start().waitFor(); if (pullResult > 0) { throw new RuntimeException("Pulling container image '" + containerImage + "' completed unsuccessfully"); } @@ -86,7 +89,7 @@ public void start() throws IOException { } List args = new ArrayList<>(); - args.add(DOCKER_BINARY); // TODO: determine this dynamically? + args.add(containerRuntimeBinaryName); args.add("run"); if (!argLine.isEmpty()) { args.addAll(argLine); @@ -149,6 +152,10 @@ public void start() throws IOException { } } + private String determineBinary() { + return ContainerRuntimeUtil.detectContainerRuntime().getExecutableName(); + } + private int getRandomPort() throws IOException { try (ServerSocket socket = new ServerSocket(0)) { return socket.getLocalPort(); @@ -180,7 +187,8 @@ private String convertPropertyToEnVar(String property) { @Override public void close() { try { - Process dockerStopProcess = new ProcessBuilder(DOCKER_BINARY, "stop", containerName).redirectError(DISCARD) + Process dockerStopProcess = new ProcessBuilder(containerRuntimeBinaryName, "stop", containerName) + .redirectError(DISCARD) .redirectOutput(DISCARD).start(); dockerStopProcess.waitFor(10, TimeUnit.SECONDS); } catch (IOException | InterruptedException e) {