Skip to content
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

Use container runtime detection in @QuarkusIntegrationTest #24490

Merged
merged 1 commit into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.deployment.util;
package io.quarkus.runtime.util;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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");
}
Expand All @@ -86,7 +89,7 @@ public void start() throws IOException {
}

List<String> args = new ArrayList<>();
args.add(DOCKER_BINARY); // TODO: determine this dynamically?
args.add(containerRuntimeBinaryName);
args.add("run");
if (!argLine.isEmpty()) {
args.addAll(argLine);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down