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

[2.16] Enables Podman and Docker Windows quarkus-container-image-docker testing #31491

Closed
wants to merge 4 commits into from
Closed
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 @@ -175,7 +175,7 @@ private static class DockerBinaryStrategy implements Strategy {

private DockerBinaryStrategy(boolean silent) {
this.silent = silent;
this.binary = ConfigProvider.getConfig().getOptionalValue("quarkus.docker.executable-name", String.class)
this.binary = ConfigProvider.getConfig().getOptionalValue("quarkus.native.container-runtime", String.class)
.orElse("docker");
}

Expand All @@ -194,7 +194,7 @@ public Result get() {
try {
OutputFilter filter = new OutputFilter();
if (ExecUtil.execWithTimeout(new File("."), filter, Duration.ofMillis(DOCKER_CMD_CHECK_TIMEOUT),
"docker", "version", "--format", "'{{.Server.Version}}'")) {
binary, "version", "--format", "'{{.Server.Version}}'")) {
LOGGER.debugf("Docker daemon found. Version: %s", filter.getOutput());
return Result.AVAILABLE;
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.quarkus.deployment.pkg.steps;

import static io.quarkus.deployment.pkg.steps.LinuxIDUtil.getLinuxID;
import static io.quarkus.runtime.util.ContainerRuntimeUtil.detectContainerRuntime;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -37,6 +38,7 @@ public class AppCDSBuildStep {
public static final String CLASSES_LIST_FILE_NAME = "classes.lst";
private static final String CONTAINER_IMAGE_BASE_BUILD_DIR = "/tmp/quarkus";
private static final String CONTAINER_IMAGE_APPCDS_DIR = CONTAINER_IMAGE_BASE_BUILD_DIR + "/appcds";
public static final String DOCKER_EXECUTABLE = detectContainerRuntime().getExecutableName();

@BuildStep(onlyIf = AppCDSRequired.class)
public void requested(OutputTargetBuildItem outputTarget, BuildProducer<AppCDSRequestedBuildItem> producer)
Expand Down Expand Up @@ -202,7 +204,7 @@ private Path createClassesList(JarBuildItem jarResult,
private List<String> dockerRunCommands(OutputTargetBuildItem outputTarget, String containerImage,
String containerWorkingDir) {
List<String> command = new ArrayList<>(10);
command.add("docker");
command.add(DOCKER_EXECUTABLE);
command.add("run");
command.add("-v");
command.add(outputTarget.getOutputDirectory().toAbsolutePath().toString() + ":" + CONTAINER_IMAGE_BASE_BUILD_DIR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
import java.util.List;

import org.apache.commons.lang3.SystemUtils;
import org.jboss.logging.Logger;
import org.eclipse.microprofile.config.ConfigProvider;

import io.quarkus.deployment.pkg.NativeConfig;
import io.quarkus.deployment.util.FileUtil;
import io.quarkus.runtime.util.ContainerRuntimeUtil;

public class NativeImageBuildLocalContainerRunner extends NativeImageBuildContainerRunner {

private static final Logger LOGGER = Logger.getLogger(NativeImageBuildLocalContainerRunner.class.getName());
public static final String DOCKER_EXECUTABLE = ConfigProvider.getConfig()
.getOptionalValue("quarkus.native.container-runtime", String.class).orElse("docker");

public NativeImageBuildLocalContainerRunner(NativeConfig nativeConfig, Path outputDir) {
super(nativeConfig, outputDir);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.quarkus.deployment.pkg.steps;

import static io.quarkus.deployment.pkg.steps.NativeImageBuildLocalContainerRunner.DOCKER_EXECUTABLE;
import static org.assertj.core.api.Assertions.assertThat;

import java.nio.file.Path;
Expand All @@ -25,33 +26,36 @@ void testBuilderImageBeingPickedUp() {

nativeConfig.builderImage = "graalvm";
localRunner = new NativeImageBuildLocalContainerRunner(nativeConfig, Path.of("/tmp"));
command = localRunner.buildCommand("docker", Collections.emptyList(), Collections.emptyList());
command = localRunner.buildCommand(DOCKER_EXECUTABLE, Collections.emptyList(), Collections.emptyList());
found = false;
for (String part : command) {
if (part.contains("ubi-quarkus-graalvmce-builder-image")) {
found = true;
break;
}
}
assertThat(found).isTrue();

nativeConfig.builderImage = "mandrel";
localRunner = new NativeImageBuildLocalContainerRunner(nativeConfig, Path.of("/tmp"));
command = localRunner.buildCommand("docker", Collections.emptyList(), Collections.emptyList());
command = localRunner.buildCommand(DOCKER_EXECUTABLE, Collections.emptyList(), Collections.emptyList());
found = false;
for (String part : command) {
if (part.contains("ubi-quarkus-mandrel-builder-image")) {
found = true;
break;
}
}
assertThat(found).isTrue();

nativeConfig.builderImage = "RandomString";
localRunner = new NativeImageBuildLocalContainerRunner(nativeConfig, Path.of("/tmp"));
command = localRunner.buildCommand("docker", Collections.emptyList(), Collections.emptyList());
command = localRunner.buildCommand(DOCKER_EXECUTABLE, Collections.emptyList(), Collections.emptyList());
found = false;
for (String part : command) {
if (part.equals("RandomString")) {
found = true;
break;
}
}
assertThat(found).isTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import org.eclipse.microprofile.config.ConfigProvider;
import org.jboss.logging.Logger;

import io.smallrye.config.SmallRyeConfig;

public final class ContainerRuntimeUtil {

private static final Logger log = Logger.getLogger(ContainerRuntimeUtil.class);
private static final String DOCKER_EXECUTABLE = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class)
.getOptionalValue("quarkus.native.container-runtime", String.class).orElse(null);

private ContainerRuntimeUtil() {
}
Expand All @@ -30,6 +36,17 @@ public static ContainerRuntime detectContainerRuntime() {
// podman version 2.1.1
String podmanVersionOutput = getVersionOutputFor(ContainerRuntime.PODMAN);
boolean podmanAvailable = podmanVersionOutput.startsWith("podman version");
if (DOCKER_EXECUTABLE != null) {
if (DOCKER_EXECUTABLE.trim().equalsIgnoreCase("docker") && dockerAvailable) {
return ContainerRuntime.DOCKER;
} else if (DOCKER_EXECUTABLE.trim().equalsIgnoreCase("podman") && podmanAvailable) {
return ContainerRuntime.PODMAN;
} else {
log.warn("quarkus.native.container-runtime config property must be set to either podman or docker " +
"and the executable must be available. Ignoring it.");
}
}

if (dockerAvailable) {
// Check if "docker" is an alias to "podman"
if (dockerVersionOutput.equals(podmanVersionOutput)) {
Expand Down Expand Up @@ -65,31 +82,37 @@ private static String getVersionOutputFor(ContainerRuntime containerRuntime) {

private static boolean getRootlessStateFor(ContainerRuntime containerRuntime) {
Process rootlessProcess = null;
ProcessBuilder pb = null;
try {
ProcessBuilder pb = new ProcessBuilder(containerRuntime.getExecutableName(), "info")
.redirectErrorStream(true);
pb = new ProcessBuilder(containerRuntime.getExecutableName(), "info").redirectErrorStream(true);
rootlessProcess = pb.start();
int exitCode = rootlessProcess.waitFor();
if (exitCode != 0) {
log.warnf("Command \"%s\" exited with error code %d. " +
"Rootless container runtime detection might not be reliable.",
containerRuntime.getExecutableName(), exitCode);
"Rootless container runtime detection might not be reliable or the container service is not running at all.",
String.join(" ", pb.command()), exitCode);
}
try (InputStream inputStream = rootlessProcess.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) {
Predicate<String> stringPredicate;
// Docker includes just "rootless" under SecurityOptions, while podman includes "rootless: <boolean>"
if (containerRuntime == ContainerRuntime.DOCKER) {
stringPredicate = line -> line.trim().equals("rootless");
if (exitCode != 0) {
log.debugf("Command \"%s\" output: %s", String.join(" ", pb.command()),
bufferedReader.lines().collect(Collectors.joining(System.lineSeparator())));
return false;
} else {
stringPredicate = line -> line.trim().equals("rootless: true");
Predicate<String> stringPredicate;
// Docker includes just "rootless" under SecurityOptions, while podman includes "rootless: <boolean>"
if (containerRuntime == ContainerRuntime.DOCKER) {
stringPredicate = line -> line.trim().equals("rootless");
} else {
stringPredicate = line -> line.trim().equals("rootless: true");
}
return bufferedReader.lines().anyMatch(stringPredicate);
}
return bufferedReader.lines().anyMatch(stringPredicate);
}
} catch (IOException | InterruptedException e) {
// If an exception is thrown in the process, assume we are not running rootless (default docker installation)
log.debugf(e, "Failure to read info output from %s", containerRuntime.getExecutableName());
log.debugf(e, "Failure to read info output from %s", String.join(" ", pb.command()));
return false;
} finally {
if (rootlessProcess != null) {
Expand Down
41 changes: 39 additions & 2 deletions integration-tests/awt/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-multipart</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-container-image-docker</artifactId>
</dependency>

<!-- test dependencies -->
<dependency>
Expand All @@ -45,6 +49,8 @@
<scope>test</scope>
</dependency>



<!-- Minimal test dependencies to *-deployment artifacts for consistent build order -->
<dependency>
<groupId>io.quarkus</groupId>
Expand All @@ -59,7 +65,6 @@
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-multipart-deployment</artifactId>
Expand Down Expand Up @@ -99,7 +104,19 @@
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-container-image-docker-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -128,6 +145,26 @@
<reuseForks>false</reuseForks>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<systemPropertyVariables>
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
<quarkus.http.host>localhost</quarkus.http.host>
<quarkus.http.port>8081</quarkus.http.port>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
15 changes: 15 additions & 0 deletions integration-tests/awt/src/main/docker/Dockerfile.native
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.7
# Dependencies for AWT
RUN microdnf install freetype fontconfig \
&& microdnf clean all
WORKDIR /work/
RUN chown 1001 /work \
&& chmod "g+rwX" /work \
&& chown 1001:root /work
COPY --chown=1001:root target/*-runner /work/application
# Permissions fix for Windows
RUN chmod "ugo+x" /work/application
EXPOSE 8081
USER 1001

CMD ["./application", "-Dquarkus.http.host=0.0.0.0"]
Loading