From 3556287ff8a70ac00ef0c403ff9148ef40182398 Mon Sep 17 00:00:00 2001 From: Ozan Gunalp Date: Wed, 20 Apr 2022 13:01:47 +0100 Subject: [PATCH] DockerStatusBuildItem for caching isDockerWorking status. * Reduce socket timeout for checking docker listening on DOCKER_HOST. * Timeout for checking docker commands (cherry picked from commit 418d986f7ea21f93aef3490921f436612bcfe141) --- .../deployment/DockerStatusProcessor.java | 13 ++ .../quarkus/deployment/IsDockerWorking.java | 13 +- .../builditem/DockerStatusBuildItem.java | 21 +++ .../io/quarkus/deployment/util/ExecUtil.java | 130 ++++++++++++++++-- .../docker/deployment/DockerProcessor.java | 10 +- .../DevServicesDatasourceProcessor.java | 12 +- .../deployment/DevServicesProcessor.java | 24 ++-- .../DevServicesElasticsearchProcessor.java | 13 +- .../InfinispanDevServiceProcessor.java | 15 +- .../deployment/DevServicesKafkaProcessor.java | 11 +- .../deployment/DevServicesMongoProcessor.java | 13 +- .../KeycloakDevServicesProcessor.java | 11 +- .../deployment/DevServicesRedisProcessor.java | 17 +-- .../DevServicesApicurioRegistryProcessor.java | 12 +- .../deployment/AmqpDevServicesProcessor.java | 14 +- .../RabbitMQDevServicesProcessor.java | 13 +- 16 files changed, 247 insertions(+), 95 deletions(-) create mode 100644 core/deployment/src/main/java/io/quarkus/deployment/DockerStatusProcessor.java create mode 100644 core/deployment/src/main/java/io/quarkus/deployment/builditem/DockerStatusBuildItem.java diff --git a/core/deployment/src/main/java/io/quarkus/deployment/DockerStatusProcessor.java b/core/deployment/src/main/java/io/quarkus/deployment/DockerStatusProcessor.java new file mode 100644 index 0000000000000..03b5d8b30e213 --- /dev/null +++ b/core/deployment/src/main/java/io/quarkus/deployment/DockerStatusProcessor.java @@ -0,0 +1,13 @@ +package io.quarkus.deployment; + +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.builditem.DockerStatusBuildItem; +import io.quarkus.deployment.builditem.LaunchModeBuildItem; + +public class DockerStatusProcessor { + + @BuildStep + DockerStatusBuildItem IsDockerWorking(LaunchModeBuildItem launchMode) { + return new DockerStatusBuildItem(new IsDockerWorking(launchMode.getLaunchMode().isDevOrTest())); + } +} diff --git a/core/deployment/src/main/java/io/quarkus/deployment/IsDockerWorking.java b/core/deployment/src/main/java/io/quarkus/deployment/IsDockerWorking.java index d47bfa597df92..861e77cb98b0f 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/IsDockerWorking.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/IsDockerWorking.java @@ -7,9 +7,11 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.lang.reflect.InvocationTargetException; +import java.net.InetSocketAddress; import java.net.Socket; import java.net.URI; import java.net.URISyntaxException; +import java.time.Duration; import java.util.List; import java.util.Optional; import java.util.function.BooleanSupplier; @@ -25,6 +27,8 @@ public class IsDockerWorking implements BooleanSupplier { private static final Logger LOGGER = Logger.getLogger(IsDockerWorking.class.getName()); + public static final int DOCKER_HOST_CHECK_TIMEOUT = 1000; + public static final int DOCKER_CMD_CHECK_TIMEOUT = 3000; private final List strategies; @@ -40,6 +44,7 @@ public IsDockerWorking(boolean silent) { @Override public boolean getAsBoolean() { for (Strategy strategy : strategies) { + LOGGER.debugf("Checking Docker Environment using strategy %s", strategy.getClass().getName()); Result result = strategy.get(); if (result == Result.AVAILABLE) { return true; @@ -113,7 +118,8 @@ public Result get() { if (dockerHost != null && !dockerHost.startsWith("unix:")) { try { URI url = new URI(dockerHost); - try (Socket s = new Socket(url.getHost(), url.getPort())) { + try (Socket s = new Socket()) { + s.connect(new InetSocketAddress(url.getHost(), url.getPort()), DOCKER_HOST_CHECK_TIMEOUT); return Result.AVAILABLE; } catch (IOException e) { LOGGER.warnf( @@ -143,7 +149,7 @@ private DockerBinaryStrategy(boolean silent) { @Override public Result get() { try { - if (!ExecUtil.execSilent(binary, "-v")) { + if (!ExecUtil.execSilentWithTimeout(Duration.ofMillis(DOCKER_CMD_CHECK_TIMEOUT), binary, "-v")) { LOGGER.warnf("'%s -v' returned an error code. Make sure your Docker binary is correct", binary); return Result.UNKNOWN; } @@ -154,7 +160,8 @@ public Result get() { try { OutputFilter filter = new OutputFilter(); - if (ExecUtil.exec(new File("."), filter, "docker", "version", "--format", "'{{.Server.Version}}'")) { + if (ExecUtil.execWithTimeout(new File("."), filter, Duration.ofMillis(DOCKER_CMD_CHECK_TIMEOUT), + "docker", "version", "--format", "'{{.Server.Version}}'")) { LOGGER.debugf("Docker daemon found. Version: %s", filter.getOutput()); return Result.AVAILABLE; } else { diff --git a/core/deployment/src/main/java/io/quarkus/deployment/builditem/DockerStatusBuildItem.java b/core/deployment/src/main/java/io/quarkus/deployment/builditem/DockerStatusBuildItem.java new file mode 100644 index 0000000000000..9309683477926 --- /dev/null +++ b/core/deployment/src/main/java/io/quarkus/deployment/builditem/DockerStatusBuildItem.java @@ -0,0 +1,21 @@ +package io.quarkus.deployment.builditem; + +import io.quarkus.builder.item.SimpleBuildItem; +import io.quarkus.deployment.IsDockerWorking; + +public final class DockerStatusBuildItem extends SimpleBuildItem { + + private final IsDockerWorking isDockerWorking; + private Boolean cachedStatus; + + public DockerStatusBuildItem(IsDockerWorking isDockerWorking) { + this.isDockerWorking = isDockerWorking; + } + + public synchronized boolean isDockerAvailable() { + if (cachedStatus == null) { + cachedStatus = isDockerWorking.getAsBoolean(); + } + return cachedStatus; + } +} diff --git a/core/deployment/src/main/java/io/quarkus/deployment/util/ExecUtil.java b/core/deployment/src/main/java/io/quarkus/deployment/util/ExecUtil.java index 88d7c9b52d8da..51bd4dd8cb9df 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/util/ExecUtil.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/util/ExecUtil.java @@ -6,6 +6,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.time.Duration; +import java.util.concurrent.TimeUnit; import java.util.function.Function; import org.jboss.logging.Logger; @@ -17,6 +19,8 @@ public class ExecUtil { private static final Function PRINT_OUTPUT = i -> new HandleOutput(i); private static final Function SILENT = i -> new HandleOutput(i, Logger.Level.DEBUG); + private static final int PROCESS_CHECK_INTERVAL = 500; + private static class HandleOutput implements Runnable { private final InputStream is; @@ -60,6 +64,18 @@ public static boolean exec(String command, String... args) { return exec(new File("."), command, args); } + /** + * Execute the specified command until the given timeout from within the current directory. + * + * @param timeout The timeout + * @param command The command + * @param args The command arguments + * @return true if commands where executed successfully + */ + public static boolean execWithTimeout(Duration timeout, String command, String... args) { + return execWithTimeout(new File("."), timeout, command, args); + } + /** * Execute the specified command from within the current directory and hide the output. * @@ -71,6 +87,18 @@ public static boolean execSilent(String command, String... args) { return execSilent(new File("."), command, args); } + /** + * Execute the specified command until the given timeout from within the current directory and hide the output. + * + * @param timeout The timeout + * @param command The command + * @param args The command arguments + * @return true if commands where executed successfully + */ + public static boolean execSilentWithTimeout(Duration timeout, String command, String... args) { + return execSilentWithTimeout(new File("."), timeout, command, args); + } + /** * Execute the specified command from within the specified directory. * @@ -83,6 +111,19 @@ public static boolean exec(File directory, String command, String... args) { return exec(directory, PRINT_OUTPUT, command, args); } + /** + * Execute the specified command until the given timeout from within the specified directory. + * + * @param directory The directory + * @param timeout The timeout + * @param command The command + * @param args The command arguments + * @return true if commands where executed successfully + */ + public static boolean execWithTimeout(File directory, Duration timeout, String command, String... args) { + return execWithTimeout(directory, PRINT_OUTPUT, timeout, command, args); + } + /** * Execute the specified command from within the specified directory and hide the output. * @@ -95,6 +136,19 @@ public static boolean execSilent(File directory, String command, String... args) return exec(directory, SILENT, command, args); } + /** + * Execute the specified command until the given timeout from within the specified directory and hide the output. + * + * @param directory The directory + * @param timeout The timeout + * @param command The command + * @param args The command arguments + * @return true if commands where executed successfully + */ + public static boolean execSilentWithTimeout(File directory, Duration timeout, String command, String... args) { + return execWithTimeout(directory, SILENT, timeout, command, args); + } + /** * Execute the specified command from within the specified directory. * The method allows specifying an output filter that processes the command output. @@ -107,27 +161,87 @@ public static boolean execSilent(File directory, String command, String... args) */ public static boolean exec(File directory, Function outputFilterFunction, String command, String... args) { - Process process = null; + try { + Process process = startProcess(directory, command, args); + outputFilterFunction.apply(process.getInputStream()); + process.waitFor(); + return process.exitValue() == 0; + } catch (InterruptedException e) { + return false; + } + } + + /** + * Execute the specified command until the given timeout from within the specified directory. + * The method allows specifying an output filter that processes the command output. + * + * @param directory The directory + * @param outputFilterFunction A {@link Function} that gets an {@link InputStream} and returns an outputFilter. + * @param timeout The timeout + * @param command The command + * @param args The command arguments + * @return true if commands where executed successfully + */ + public static boolean execWithTimeout(File directory, Function outputFilterFunction, + Duration timeout, String command, String... args) { + try { + Process process = startProcess(directory, command, args); + Thread t = new Thread(outputFilterFunction.apply(process.getInputStream())); + t.setName("Process stdout"); + t.setDaemon(true); + t.start(); + process.waitFor(timeout.toMillis(), TimeUnit.MILLISECONDS); + destroyProcess(process); + return process.exitValue() == 0; + } catch (InterruptedException e) { + return false; + } + } + + /** + * Start a process executing given command with arguments within the specified directory. + * + * @param directory The directory + * @param command The command + * @param args The command arguments + * @return the process + */ + public static Process startProcess(File directory, String command, String... args) { try { String[] cmd = new String[args.length + 1]; cmd[0] = command; if (args.length > 0) { System.arraycopy(args, 0, cmd, 1, args.length); } - process = new ProcessBuilder() + return new ProcessBuilder() .directory(directory) .command(cmd) .redirectErrorStream(true) .start(); - - outputFilterFunction.apply(process.getInputStream()).run(); - process.waitFor(); } catch (IOException e) { throw new RuntimeException("Input/Output error while executing command.", e); - } catch (InterruptedException e) { - return false; } - return process != null && process.exitValue() == 0; + } + + /** + * Kill the process, if still alive, kill it forcibly + * + * @param process the process to kill + */ + public static void destroyProcess(Process process) { + process.destroy(); + int i = 0; + while (process.isAlive() && i++ < 10) { + try { + process.waitFor(PROCESS_CHECK_INTERVAL, TimeUnit.MILLISECONDS); + } catch (InterruptedException ignored) { + Thread.currentThread().interrupt(); + } + } + + if (process.isAlive()) { + process.destroyForcibly(); + } } } diff --git a/extensions/container-image/container-image-docker/deployment/src/main/java/io/quarkus/container/image/docker/deployment/DockerProcessor.java b/extensions/container-image/container-image-docker/deployment/src/main/java/io/quarkus/container/image/docker/deployment/DockerProcessor.java index 1f470c572d3bb..d4552db4ddf1c 100644 --- a/extensions/container-image/container-image-docker/deployment/src/main/java/io/quarkus/container/image/docker/deployment/DockerProcessor.java +++ b/extensions/container-image/container-image-docker/deployment/src/main/java/io/quarkus/container/image/docker/deployment/DockerProcessor.java @@ -30,10 +30,10 @@ import io.quarkus.container.spi.ContainerImageBuilderBuildItem; import io.quarkus.container.spi.ContainerImageInfoBuildItem; import io.quarkus.container.spi.ContainerImagePushRequestBuildItem; -import io.quarkus.deployment.IsDockerWorking; import io.quarkus.deployment.IsNormalNotRemoteDev; import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.builditem.DockerStatusBuildItem; import io.quarkus.deployment.pkg.PackageConfig; import io.quarkus.deployment.pkg.builditem.AppCDSResultBuildItem; import io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem; @@ -55,8 +55,6 @@ public class DockerProcessor { private static final String DOCKER_DIRECTORY_NAME = "docker"; static final String DOCKER_CONTAINER_IMAGE_NAME = "docker"; - private final IsDockerWorking isDockerWorking = new IsDockerWorking(); - @BuildStep public AvailableContainerImageExtensionBuildItem availability() { return new AvailableContainerImageExtensionBuildItem(DOCKER); @@ -64,6 +62,7 @@ public AvailableContainerImageExtensionBuildItem availability() { @BuildStep(onlyIf = { IsNormalNotRemoteDev.class, DockerBuild.class }, onlyIfNot = NativeBuild.class) public void dockerBuildFromJar(DockerConfig dockerConfig, + DockerStatusBuildItem dockerStatusBuildItem, ContainerImageConfig containerImageConfig, OutputTargetBuildItem out, ContainerImageInfoBuildItem containerImageInfo, @@ -83,7 +82,7 @@ public void dockerBuildFromJar(DockerConfig dockerConfig, return; } - if (!isDockerWorking.getAsBoolean()) { + if (!dockerStatusBuildItem.isDockerAvailable()) { throw new RuntimeException("Unable to build docker image. Please check your docker installation"); } @@ -116,6 +115,7 @@ public void dockerBuildFromJar(DockerConfig dockerConfig, @BuildStep(onlyIf = { IsNormalNotRemoteDev.class, NativeBuild.class, DockerBuild.class }) public void dockerBuildFromNativeImage(DockerConfig dockerConfig, + DockerStatusBuildItem dockerStatusBuildItem, ContainerImageConfig containerImageConfig, ContainerImageInfoBuildItem containerImage, Optional buildRequest, @@ -134,7 +134,7 @@ public void dockerBuildFromNativeImage(DockerConfig dockerConfig, return; } - if (!isDockerWorking.getAsBoolean()) { + if (!dockerStatusBuildItem.isDockerAvailable()) { throw new RuntimeException("Unable to build docker image. Please check your docker installation"); } diff --git a/extensions/datasource/deployment/src/main/java/io/quarkus/datasource/deployment/devservices/DevServicesDatasourceProcessor.java b/extensions/datasource/deployment/src/main/java/io/quarkus/datasource/deployment/devservices/DevServicesDatasourceProcessor.java index cb85cc34041f3..db479d3c02995 100644 --- a/extensions/datasource/deployment/src/main/java/io/quarkus/datasource/deployment/devservices/DevServicesDatasourceProcessor.java +++ b/extensions/datasource/deployment/src/main/java/io/quarkus/datasource/deployment/devservices/DevServicesDatasourceProcessor.java @@ -20,13 +20,13 @@ import io.quarkus.datasource.deployment.spi.DevServicesDatasourceResultBuildItem; import io.quarkus.datasource.runtime.DataSourceBuildTimeConfig; import io.quarkus.datasource.runtime.DataSourcesBuildTimeConfig; -import io.quarkus.deployment.IsDockerWorking; import io.quarkus.deployment.IsNormal; import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.deployment.builditem.CuratedApplicationShutdownBuildItem; import io.quarkus.deployment.builditem.DevServicesResultBuildItem; import io.quarkus.deployment.builditem.DevServicesResultBuildItem.RunningDevService; +import io.quarkus.deployment.builditem.DockerStatusBuildItem; import io.quarkus.deployment.builditem.LaunchModeBuildItem; import io.quarkus.deployment.console.ConsoleInstalledBuildItem; import io.quarkus.deployment.console.StartupLogCompressor; @@ -45,10 +45,9 @@ public class DevServicesDatasourceProcessor { static volatile boolean first = true; - private final IsDockerWorking isDockerWorking = new IsDockerWorking(true); - @BuildStep(onlyIfNot = IsNormal.class, onlyIf = GlobalDevServicesConfig.Enabled.class) DevServicesDatasourceResultBuildItem launchDatabases(CurateOutcomeBuildItem curateOutcomeBuildItem, + DockerStatusBuildItem dockerStatusBuildItem, List installedDrivers, List devDBProviders, DataSourcesBuildTimeConfig dataSourceBuildTimeConfig, @@ -127,7 +126,8 @@ DevServicesDatasourceResultBuildItem launchDatabases(CurateOutcomeBuildItem cura !dataSourceBuildTimeConfig.namedDataSources.isEmpty(), devDBProviderMap, dataSourceBuildTimeConfig.defaultDataSource, - configHandlersByDbType, propertiesMap, launchMode.getLaunchMode(), consoleInstalledBuildItem, + configHandlersByDbType, propertiesMap, + dockerStatusBuildItem, launchMode.getLaunchMode(), consoleInstalledBuildItem, loggingSetupBuildItem, globalDevServicesConfig); if (defaultDevService != null) { runningDevServices.add(defaultDevService); @@ -137,6 +137,7 @@ DevServicesDatasourceResultBuildItem launchDatabases(CurateOutcomeBuildItem cura RunningDevService namedDevService = startDevDb(entry.getKey(), curateOutcomeBuildItem, installedDrivers, true, devDBProviderMap, entry.getValue(), configHandlersByDbType, propertiesMap, + dockerStatusBuildItem, launchMode.getLaunchMode(), consoleInstalledBuildItem, loggingSetupBuildItem, globalDevServicesConfig); if (namedDevService != null) { runningDevServices.add(namedDevService); @@ -187,6 +188,7 @@ private RunningDevService startDevDb(String dbName, Map devDBProviders, DataSourceBuildTimeConfig dataSourceBuildTimeConfig, Map> configurationHandlerBuildItems, Map propertiesMap, + DockerStatusBuildItem dockerStatusBuildItem, LaunchMode launchMode, Optional consoleInstalledBuildItem, LoggingSetupBuildItem loggingSetupBuildItem, GlobalDevServicesConfig globalDevServicesConfig) { boolean explicitlyDisabled = !(dataSourceBuildTimeConfig.devservices.enabled.orElse(true)); @@ -232,7 +234,7 @@ private RunningDevService startDevDb(String dbName, } String prettyName = dbName == null ? "the default datasource" : " datasource '" + dbName + "'"; - if (devDbProvider.isDockerRequired() && !isDockerWorking.getAsBoolean()) { + if (devDbProvider.isDockerRequired() && !dockerStatusBuildItem.isDockerAvailable()) { String message = "Please configure the datasource URL for " + prettyName + " or ensure the Docker daemon is up and running."; diff --git a/extensions/devservices/deployment/src/main/java/io/quarkus/devservices/deployment/DevServicesProcessor.java b/extensions/devservices/deployment/src/main/java/io/quarkus/devservices/deployment/DevServicesProcessor.java index caf05ad26ef7e..a7a5a035961c7 100644 --- a/extensions/devservices/deployment/src/main/java/io/quarkus/devservices/deployment/DevServicesProcessor.java +++ b/extensions/devservices/deployment/src/main/java/io/quarkus/devservices/deployment/DevServicesProcessor.java @@ -19,12 +19,12 @@ import com.github.dockerjava.api.model.ContainerNetworkSettings; import io.quarkus.deployment.IsDevelopment; -import io.quarkus.deployment.IsDockerWorking; import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.deployment.builditem.ConsoleCommandBuildItem; import io.quarkus.deployment.builditem.DevServicesLauncherConfigResultBuildItem; import io.quarkus.deployment.builditem.DevServicesResultBuildItem; +import io.quarkus.deployment.builditem.DockerStatusBuildItem; import io.quarkus.deployment.builditem.LaunchModeBuildItem; import io.quarkus.deployment.console.ConsoleCommand; import io.quarkus.deployment.console.ConsoleStateManager; @@ -36,20 +36,19 @@ public class DevServicesProcessor { private static final String EXEC_FORMAT = "docker exec -it %s /bin/bash"; - private final IsDockerWorking isDockerWorking = new IsDockerWorking(true); - static volatile ConsoleStateManager.ConsoleContext context; static volatile boolean logForwardEnabled = false; static Map containerLogForwarders = new HashMap<>(); @BuildStep(onlyIf = { IsDevelopment.class }) public List config( + DockerStatusBuildItem dockerStatusBuildItem, BuildProducer commandBuildItemBuildProducer, LaunchModeBuildItem launchModeBuildItem, Optional devServicesLauncherConfig, List devServicesResults) { - List serviceDescriptions = buildServiceDescriptions(devServicesResults, - devServicesLauncherConfig); + List serviceDescriptions = buildServiceDescriptions( + dockerStatusBuildItem, devServicesResults, devServicesLauncherConfig); for (DevServiceDescriptionBuildItem devService : serviceDescriptions) { if (devService.hasContainerInfo()) { @@ -72,8 +71,8 @@ public List config( } context.reset( new ConsoleCommand('c', "Show dev services containers", null, () -> { - List descriptions = buildServiceDescriptions(devServicesResults, - devServicesLauncherConfig); + List descriptions = buildServiceDescriptions( + dockerStatusBuildItem, devServicesResults, devServicesLauncherConfig); StringBuilder builder = new StringBuilder(); builder.append("\n\n") .append(RED + "==" + RESET + " " + UNDERLINE + "Dev Services" + NO_UNDERLINE) @@ -91,14 +90,16 @@ public List config( return serviceDescriptions; } - private List buildServiceDescriptions(List devServicesResults, + private List buildServiceDescriptions( + DockerStatusBuildItem dockerStatusBuildItem, + List devServicesResults, Optional devServicesLauncherConfig) { // Fetch container infos Set containerIds = devServicesResults.stream() .map(DevServicesResultBuildItem::getContainerId) .filter(Objects::nonNull) .collect(Collectors.toSet()); - Map containerInfos = fetchContainerInfos(containerIds); + Map containerInfos = fetchContainerInfos(dockerStatusBuildItem, containerIds); // Build descriptions Set configKeysFromDevServices = new HashSet<>(); List descriptions = new ArrayList<>(); @@ -121,8 +122,9 @@ private List buildServiceDescriptions(List fetchContainerInfos(Set containerIds) { - if (containerIds.isEmpty() || !isDockerWorking.getAsBoolean()) { + private Map fetchContainerInfos(DockerStatusBuildItem dockerStatusBuildItem, + Set containerIds) { + if (containerIds.isEmpty() || !dockerStatusBuildItem.isDockerAvailable()) { return Collections.emptyMap(); } return DockerClientFactory.lazyClient().listContainersCmd() diff --git a/extensions/elasticsearch-rest-client-common/deployment/src/main/java/io/quarkus/elasticsearch/restclient/common/deployment/DevServicesElasticsearchProcessor.java b/extensions/elasticsearch-rest-client-common/deployment/src/main/java/io/quarkus/elasticsearch/restclient/common/deployment/DevServicesElasticsearchProcessor.java index 974ea789c5a55..bdfabafe8418e 100644 --- a/extensions/elasticsearch-rest-client-common/deployment/src/main/java/io/quarkus/elasticsearch/restclient/common/deployment/DevServicesElasticsearchProcessor.java +++ b/extensions/elasticsearch-rest-client-common/deployment/src/main/java/io/quarkus/elasticsearch/restclient/common/deployment/DevServicesElasticsearchProcessor.java @@ -16,12 +16,12 @@ import io.quarkus.builder.BuildException; import io.quarkus.deployment.Feature; -import io.quarkus.deployment.IsDockerWorking; import io.quarkus.deployment.IsNormal; import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.deployment.builditem.CuratedApplicationShutdownBuildItem; import io.quarkus.deployment.builditem.DevServicesResultBuildItem; import io.quarkus.deployment.builditem.DevServicesSharedNetworkBuildItem; +import io.quarkus.deployment.builditem.DockerStatusBuildItem; import io.quarkus.deployment.builditem.LaunchModeBuildItem; import io.quarkus.deployment.console.ConsoleInstalledBuildItem; import io.quarkus.deployment.console.StartupLogCompressor; @@ -52,10 +52,9 @@ public class DevServicesElasticsearchProcessor { static volatile ElasticsearchDevServicesBuildTimeConfig cfg; static volatile boolean first = true; - private final IsDockerWorking isDockerWorking = new IsDockerWorking(true); - @BuildStep(onlyIfNot = IsNormal.class, onlyIf = GlobalDevServicesConfig.Enabled.class) public DevServicesResultBuildItem startElasticsearchDevService( + DockerStatusBuildItem dockerStatusBuildItem, LaunchModeBuildItem launchMode, ElasticsearchDevServicesBuildTimeConfig configuration, List devServicesSharedNetworkBuildItem, @@ -86,7 +85,7 @@ public DevServicesResultBuildItem startElasticsearchDevService( (launchMode.isTest() ? "(test) " : "") + "Elasticsearch Dev Services Starting:", consoleInstalledBuildItem, loggingSetupBuildItem); try { - devService = startElasticsearch(configuration, buildItemsConfig, launchMode, + devService = startElasticsearch(dockerStatusBuildItem, configuration, buildItemsConfig, launchMode, !devServicesSharedNetworkBuildItem.isEmpty(), devServicesConfig.timeout); if (devService == null) { @@ -145,7 +144,9 @@ private void shutdownElasticsearch() { } } - private DevServicesResultBuildItem.RunningDevService startElasticsearch(ElasticsearchDevServicesBuildTimeConfig config, + private DevServicesResultBuildItem.RunningDevService startElasticsearch( + DockerStatusBuildItem dockerStatusBuildItem, + ElasticsearchDevServicesBuildTimeConfig config, DevservicesElasticsearchBuildItemsConfiguration buildItemConfig, LaunchModeBuildItem launchMode, boolean useSharedNetwork, Optional timeout) throws BuildException { if (!config.enabled.orElse(true)) { @@ -162,7 +163,7 @@ private DevServicesResultBuildItem.RunningDevService startElasticsearch(Elastics } } - if (!isDockerWorking.getAsBoolean()) { + if (!dockerStatusBuildItem.isDockerAvailable()) { log.warnf("Docker isn't working, please configure the Elasticsearch hosts property (%s).", displayProperties(buildItemConfig.hostsConfigProperties)); return null; diff --git a/extensions/infinispan-client/deployment/src/main/java/io/quarkus/infinispan/client/deployment/devservices/InfinispanDevServiceProcessor.java b/extensions/infinispan-client/deployment/src/main/java/io/quarkus/infinispan/client/deployment/devservices/InfinispanDevServiceProcessor.java index f032815002ea3..8d4075e42114b 100644 --- a/extensions/infinispan-client/deployment/src/main/java/io/quarkus/infinispan/client/deployment/devservices/InfinispanDevServiceProcessor.java +++ b/extensions/infinispan-client/deployment/src/main/java/io/quarkus/infinispan/client/deployment/devservices/InfinispanDevServiceProcessor.java @@ -20,13 +20,13 @@ import org.jetbrains.annotations.NotNull; import io.quarkus.deployment.Feature; -import io.quarkus.deployment.IsDockerWorking; import io.quarkus.deployment.IsNormal; import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.deployment.builditem.CuratedApplicationShutdownBuildItem; import io.quarkus.deployment.builditem.DevServicesResultBuildItem; import io.quarkus.deployment.builditem.DevServicesResultBuildItem.RunningDevService; import io.quarkus.deployment.builditem.DevServicesSharedNetworkBuildItem; +import io.quarkus.deployment.builditem.DockerStatusBuildItem; import io.quarkus.deployment.builditem.LaunchModeBuildItem; import io.quarkus.deployment.console.ConsoleInstalledBuildItem; import io.quarkus.deployment.console.StartupLogCompressor; @@ -56,10 +56,10 @@ public class InfinispanDevServiceProcessor { private static volatile List devServices; private static volatile InfinispanClientDevServiceBuildTimeConfig.DevServiceConfiguration capturedDevServicesConfiguration; private static volatile boolean first = true; - private static volatile Boolean dockerRunning = null; @BuildStep(onlyIfNot = IsNormal.class, onlyIf = { GlobalDevServicesConfig.Enabled.class }) public List startInfinispanContainers(LaunchModeBuildItem launchMode, + DockerStatusBuildItem dockerStatusBuildItem, List devServicesSharedNetworkBuildItem, InfinispanClientDevServiceBuildTimeConfig config, Optional consoleInstalledBuildItem, @@ -91,7 +91,7 @@ public List startInfinispanContainers(LaunchModeBuil (launchMode.isTest() ? "(test) " : "") + "Infinispan Dev Services Starting:", consoleInstalledBuildItem, loggingSetupBuildItem); try { - RunningDevService devService = startContainer(config.devService.devservices, + RunningDevService devService = startContainer(dockerStatusBuildItem, config.devService.devservices, launchMode.getLaunchMode(), !devServicesSharedNetworkBuildItem.isEmpty(), devServicesConfig.timeout); if (devService == null) { @@ -112,7 +112,6 @@ public List startInfinispanContainers(LaunchModeBuil if (first) { first = false; Runnable closeTask = () -> { - dockerRunning = null; if (devServices != null) { for (Closeable closeable : devServices) { try { @@ -131,7 +130,7 @@ public List startInfinispanContainers(LaunchModeBuil return devServices.stream().map(RunningDevService::toBuildItem).collect(Collectors.toList()); } - private RunningDevService startContainer( + private RunningDevService startContainer(DockerStatusBuildItem dockerStatusBuildItem, InfinispanDevServicesConfig devServicesConfig, LaunchMode launchMode, boolean useSharedNetwork, Optional timeout) { if (!devServicesConfig.enabled) { @@ -148,11 +147,7 @@ private RunningDevService startContainer( return null; } - if (dockerRunning == null) { - dockerRunning = new IsDockerWorking.IsDockerRunningSilent().getAsBoolean(); - } - - if (!dockerRunning) { + if (!dockerStatusBuildItem.isDockerAvailable()) { log.warn("Please configure 'quarkus.infinispan-client.server-list' or get a working docker instance"); return null; } diff --git a/extensions/kafka-client/deployment/src/main/java/io/quarkus/kafka/client/deployment/DevServicesKafkaProcessor.java b/extensions/kafka-client/deployment/src/main/java/io/quarkus/kafka/client/deployment/DevServicesKafkaProcessor.java index c7ea6662fb149..22ecf83c495b7 100644 --- a/extensions/kafka-client/deployment/src/main/java/io/quarkus/kafka/client/deployment/DevServicesKafkaProcessor.java +++ b/extensions/kafka-client/deployment/src/main/java/io/quarkus/kafka/client/deployment/DevServicesKafkaProcessor.java @@ -25,13 +25,13 @@ import org.testcontainers.utility.DockerImageName; import io.quarkus.deployment.Feature; -import io.quarkus.deployment.IsDockerWorking; import io.quarkus.deployment.IsNormal; import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.deployment.builditem.CuratedApplicationShutdownBuildItem; import io.quarkus.deployment.builditem.DevServicesResultBuildItem; import io.quarkus.deployment.builditem.DevServicesResultBuildItem.RunningDevService; import io.quarkus.deployment.builditem.DevServicesSharedNetworkBuildItem; +import io.quarkus.deployment.builditem.DockerStatusBuildItem; import io.quarkus.deployment.builditem.LaunchModeBuildItem; import io.quarkus.deployment.console.ConsoleInstalledBuildItem; import io.quarkus.deployment.console.StartupLogCompressor; @@ -65,10 +65,9 @@ public class DevServicesKafkaProcessor { static volatile KafkaDevServiceCfg cfg; static volatile boolean first = true; - private final IsDockerWorking isDockerWorking = new IsDockerWorking(true); - @BuildStep(onlyIfNot = IsNormal.class, onlyIf = GlobalDevServicesConfig.Enabled.class) public DevServicesResultBuildItem startKafkaDevService( + DockerStatusBuildItem dockerStatusBuildItem, LaunchModeBuildItem launchMode, KafkaBuildTimeConfig kafkaClientBuildTimeConfig, List devServicesSharedNetworkBuildItem, @@ -91,7 +90,7 @@ public DevServicesResultBuildItem startKafkaDevService( (launchMode.isTest() ? "(test) " : "") + "Kafka Dev Services Starting:", consoleInstalledBuildItem, loggingSetupBuildItem); try { - devService = startKafka(configuration, launchMode, + devService = startKafka(dockerStatusBuildItem, configuration, launchMode, !devServicesSharedNetworkBuildItem.isEmpty(), devServicesConfig.timeout); if (devService == null) { @@ -192,7 +191,7 @@ private void shutdownBroker() { } } - private RunningDevService startKafka(KafkaDevServiceCfg config, + private RunningDevService startKafka(DockerStatusBuildItem dockerStatusBuildItem, KafkaDevServiceCfg config, LaunchModeBuildItem launchMode, boolean useSharedNetwork, Optional timeout) { if (!config.devServicesEnabled) { // explicitly disabled @@ -212,7 +211,7 @@ private RunningDevService startKafka(KafkaDevServiceCfg config, return null; } - if (!isDockerWorking.getAsBoolean()) { + if (!dockerStatusBuildItem.isDockerAvailable()) { log.warn( "Docker isn't working, please configure the Kafka bootstrap servers property (kafka.bootstrap.servers)."); return null; diff --git a/extensions/mongodb-client/deployment/src/main/java/io/quarkus/mongodb/deployment/DevServicesMongoProcessor.java b/extensions/mongodb-client/deployment/src/main/java/io/quarkus/mongodb/deployment/DevServicesMongoProcessor.java index 65d1d305585f4..a4829e429bd99 100644 --- a/extensions/mongodb-client/deployment/src/main/java/io/quarkus/mongodb/deployment/DevServicesMongoProcessor.java +++ b/extensions/mongodb-client/deployment/src/main/java/io/quarkus/mongodb/deployment/DevServicesMongoProcessor.java @@ -22,13 +22,13 @@ import com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.net.URLEncodedUtils; import io.quarkus.deployment.Feature; -import io.quarkus.deployment.IsDockerWorking; import io.quarkus.deployment.IsNormal; import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.deployment.builditem.CuratedApplicationShutdownBuildItem; import io.quarkus.deployment.builditem.DevServicesResultBuildItem; import io.quarkus.deployment.builditem.DevServicesResultBuildItem.RunningDevService; import io.quarkus.deployment.builditem.DevServicesSharedNetworkBuildItem; +import io.quarkus.deployment.builditem.DockerStatusBuildItem; import io.quarkus.deployment.builditem.LaunchModeBuildItem; import io.quarkus.deployment.console.ConsoleInstalledBuildItem; import io.quarkus.deployment.console.StartupLogCompressor; @@ -46,10 +46,9 @@ public class DevServicesMongoProcessor { static volatile Map capturedProperties; static volatile boolean first = true; - private final IsDockerWorking isDockerWorking = new IsDockerWorking(true); - @BuildStep(onlyIfNot = IsNormal.class, onlyIf = GlobalDevServicesConfig.Enabled.class) public List startMongo(List mongoConnections, + DockerStatusBuildItem dockerStatusBuildItem, MongoClientBuildTimeConfig mongoClientBuildTimeConfig, List devServicesSharedNetworkBuildItem, Optional consoleInstalledBuildItem, @@ -101,7 +100,7 @@ public List startMongo(List timeout) { + private RunningDevService startMongo(DockerStatusBuildItem dockerStatusBuildItem, String connectionName, + CapturedProperties capturedProperties, boolean useSharedNetwork, Optional timeout) { if (!capturedProperties.devServicesEnabled) { // explicitly disabled log.debug("Not starting devservices for " + (isDefault(connectionName) ? "default datasource" : connectionName) @@ -162,7 +161,7 @@ private RunningDevService startMongo(String connectionName, CapturedProperties c return null; } - if (!isDockerWorking.getAsBoolean()) { + if (!dockerStatusBuildItem.isDockerAvailable()) { log.warn("Please configure datasource URL for " + (isDefault(connectionName) ? "default datasource" : connectionName) + " or get a working docker instance"); diff --git a/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevServicesProcessor.java b/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevServicesProcessor.java index 1e08bc48ffd49..e98fb1c9acc88 100644 --- a/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevServicesProcessor.java +++ b/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevServicesProcessor.java @@ -41,7 +41,6 @@ import org.testcontainers.containers.wait.strategy.Wait; import org.testcontainers.utility.DockerImageName; -import io.quarkus.deployment.IsDockerWorking; import io.quarkus.deployment.IsNormal; import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; @@ -49,6 +48,7 @@ import io.quarkus.deployment.builditem.DevServicesResultBuildItem; import io.quarkus.deployment.builditem.DevServicesResultBuildItem.RunningDevService; import io.quarkus.deployment.builditem.DevServicesSharedNetworkBuildItem; +import io.quarkus.deployment.builditem.DockerStatusBuildItem; import io.quarkus.deployment.builditem.LaunchModeBuildItem; import io.quarkus.deployment.console.ConsoleInstalledBuildItem; import io.quarkus.deployment.console.StartupLogCompressor; @@ -123,10 +123,10 @@ public class KeycloakDevServicesProcessor { static volatile DevServicesConfig capturedDevServicesConfiguration; private static volatile boolean first = true; private static volatile FileTime capturedRealmFileLastModifiedDate; - private final IsDockerWorking isDockerWorking = new IsDockerWorking(true); @BuildStep(onlyIfNot = IsNormal.class, onlyIf = { IsEnabled.class, GlobalDevServicesConfig.Enabled.class }) public DevServicesResultBuildItem startKeycloakContainer( + DockerStatusBuildItem dockerStatusBuildItem, BuildProducer keycloakBuildItemBuildProducer, List devServicesSharedNetworkBuildItem, Optional oidcProviderBuildItem, @@ -182,7 +182,7 @@ public DevServicesResultBuildItem startKeycloakContainer( vertxInstance = Vertx.vertx(); } try { - RunningDevService newDevService = startContainer(keycloakBuildItemBuildProducer, + RunningDevService newDevService = startContainer(dockerStatusBuildItem, keycloakBuildItemBuildProducer, !devServicesSharedNetworkBuildItem.isEmpty(), devServicesConfig.timeout); if (newDevService == null) { @@ -287,7 +287,8 @@ private String getDefaultRealmName() { return capturedDevServicesConfiguration.realmName.orElse("quarkus"); } - private RunningDevService startContainer(BuildProducer keycloakBuildItemBuildProducer, + private RunningDevService startContainer(DockerStatusBuildItem dockerStatusBuildItem, + BuildProducer keycloakBuildItemBuildProducer, boolean useSharedNetwork, Optional timeout) { if (!capturedDevServicesConfiguration.enabled) { // explicitly disabled @@ -307,7 +308,7 @@ private RunningDevService startContainer(BuildProducer devServices; private static volatile Map capturedDevServicesConfiguration; private static volatile boolean first = true; - private static volatile Boolean dockerRunning = null; @BuildStep(onlyIfNot = IsNormal.class, onlyIf = { GlobalDevServicesConfig.Enabled.class }) public List startRedisContainers(LaunchModeBuildItem launchMode, + DockerStatusBuildItem dockerStatusBuildItem, List devServicesSharedNetworkBuildItem, RedisBuildTimeConfig config, Optional consoleInstalledBuildItem, @@ -100,7 +100,8 @@ public List startRedisContainers(LaunchModeBuildItem try { for (Entry entry : currentDevServicesConfiguration.entrySet()) { String connectionName = entry.getKey(); - RunningDevService devService = startContainer(connectionName, entry.getValue().devservices, + RunningDevService devService = startContainer(dockerStatusBuildItem, connectionName, + entry.getValue().devservices, launchMode.getLaunchMode(), !devServicesSharedNetworkBuildItem.isEmpty(), devServicesConfig.timeout); if (devService == null) { @@ -126,7 +127,6 @@ public List startRedisContainers(LaunchModeBuildItem if (first) { first = false; Runnable closeTask = () -> { - dockerRunning = null; if (devServices != null) { for (Closeable closeable : devServices) { try { @@ -145,7 +145,8 @@ public List startRedisContainers(LaunchModeBuildItem return devServices.stream().map(RunningDevService::toBuildItem).collect(Collectors.toList()); } - private RunningDevService startContainer(String connectionName, DevServicesConfig devServicesConfig, LaunchMode launchMode, + private RunningDevService startContainer(DockerStatusBuildItem dockerStatusBuildItem, String connectionName, + DevServicesConfig devServicesConfig, LaunchMode launchMode, boolean useSharedNetwork, Optional timeout) { if (!devServicesConfig.enabled) { // explicitly disabled @@ -163,11 +164,7 @@ private RunningDevService startContainer(String connectionName, DevServicesConfi return null; } - if (dockerRunning == null) { - dockerRunning = new IsDockerRunningSilent().getAsBoolean(); - } - - if (!dockerRunning) { + if (!dockerStatusBuildItem.isDockerAvailable()) { log.warn("Please configure quarkus.redis.hosts for " + (isDefault(connectionName) ? "default redis client" : connectionName) + " or get a working docker instance"); diff --git a/extensions/schema-registry/devservice/deployment/src/main/java/io/quarkus/apicurio/registry/devservice/DevServicesApicurioRegistryProcessor.java b/extensions/schema-registry/devservice/deployment/src/main/java/io/quarkus/apicurio/registry/devservice/DevServicesApicurioRegistryProcessor.java index 658ee0f385a85..c363046c7ef4c 100644 --- a/extensions/schema-registry/devservice/deployment/src/main/java/io/quarkus/apicurio/registry/devservice/DevServicesApicurioRegistryProcessor.java +++ b/extensions/schema-registry/devservice/deployment/src/main/java/io/quarkus/apicurio/registry/devservice/DevServicesApicurioRegistryProcessor.java @@ -13,13 +13,13 @@ import org.testcontainers.utility.DockerImageName; import io.quarkus.deployment.Feature; -import io.quarkus.deployment.IsDockerWorking; import io.quarkus.deployment.IsNormal; import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.deployment.builditem.CuratedApplicationShutdownBuildItem; import io.quarkus.deployment.builditem.DevServicesResultBuildItem; import io.quarkus.deployment.builditem.DevServicesResultBuildItem.RunningDevService; import io.quarkus.deployment.builditem.DevServicesSharedNetworkBuildItem; +import io.quarkus.deployment.builditem.DockerStatusBuildItem; import io.quarkus.deployment.builditem.LaunchModeBuildItem; import io.quarkus.deployment.console.ConsoleInstalledBuildItem; import io.quarkus.deployment.console.StartupLogCompressor; @@ -54,10 +54,9 @@ public class DevServicesApicurioRegistryProcessor { static volatile ApicurioRegistryDevServiceCfg cfg; static volatile boolean first = true; - private final IsDockerWorking isDockerWorking = new IsDockerWorking(true); - @BuildStep(onlyIfNot = IsNormal.class, onlyIf = GlobalDevServicesConfig.Enabled.class) public DevServicesResultBuildItem startApicurioRegistryDevService(LaunchModeBuildItem launchMode, + DockerStatusBuildItem dockerStatusBuildItem, ApicurioRegistryDevServicesBuildTimeConfig apicurioRegistryDevServices, List devServicesSharedNetworkBuildItem, Optional consoleInstalledBuildItem, @@ -78,7 +77,7 @@ public DevServicesResultBuildItem startApicurioRegistryDevService(LaunchModeBuil (launchMode.isTest() ? "(test) " : "") + "Apicurio Registry Dev Services Starting:", consoleInstalledBuildItem, loggingSetupBuildItem); try { - devService = startApicurioRegistry(configuration, launchMode, + devService = startApicurioRegistry(dockerStatusBuildItem, configuration, launchMode, !devServicesSharedNetworkBuildItem.isEmpty(), devServicesConfig.timeout); compressor.close(); } catch (Throwable t) { @@ -134,7 +133,8 @@ private void shutdownApicurioRegistry() { } } - private RunningDevService startApicurioRegistry(ApicurioRegistryDevServiceCfg config, LaunchModeBuildItem launchMode, + private RunningDevService startApicurioRegistry(DockerStatusBuildItem dockerStatusBuildItem, + ApicurioRegistryDevServiceCfg config, LaunchModeBuildItem launchMode, boolean useSharedNetwork, Optional timeout) { if (!config.devServicesEnabled) { // explicitly disabled @@ -158,7 +158,7 @@ private RunningDevService startApicurioRegistry(ApicurioRegistryDevServiceCfg co return null; } - if (!isDockerWorking.getAsBoolean()) { + if (!dockerStatusBuildItem.isDockerAvailable()) { log.warn("Docker isn't working, please run Apicurio Registry yourself."); return null; } diff --git a/extensions/smallrye-reactive-messaging-amqp/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/amqp/deployment/AmqpDevServicesProcessor.java b/extensions/smallrye-reactive-messaging-amqp/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/amqp/deployment/AmqpDevServicesProcessor.java index 729726736b2f4..3ba67d99a20d3 100644 --- a/extensions/smallrye-reactive-messaging-amqp/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/amqp/deployment/AmqpDevServicesProcessor.java +++ b/extensions/smallrye-reactive-messaging-amqp/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/amqp/deployment/AmqpDevServicesProcessor.java @@ -17,12 +17,12 @@ import org.testcontainers.utility.DockerImageName; import io.quarkus.deployment.Feature; -import io.quarkus.deployment.IsDockerWorking; import io.quarkus.deployment.IsNormal; import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.deployment.builditem.CuratedApplicationShutdownBuildItem; import io.quarkus.deployment.builditem.DevServicesResultBuildItem; import io.quarkus.deployment.builditem.DevServicesResultBuildItem.RunningDevService; +import io.quarkus.deployment.builditem.DockerStatusBuildItem; import io.quarkus.deployment.builditem.LaunchModeBuildItem; import io.quarkus.deployment.console.ConsoleInstalledBuildItem; import io.quarkus.deployment.console.StartupLogCompressor; @@ -62,10 +62,9 @@ public class AmqpDevServicesProcessor { static volatile AmqpDevServiceCfg cfg; static volatile boolean first = true; - private final IsDockerWorking isDockerWorking = new IsDockerWorking(true); - @BuildStep(onlyIfNot = IsNormal.class, onlyIf = GlobalDevServicesConfig.Enabled.class) public DevServicesResultBuildItem startAmqpDevService( + DockerStatusBuildItem dockerStatusBuildItem, LaunchModeBuildItem launchMode, AmqpBuildTimeConfig amqpClientBuildTimeConfig, Optional consoleInstalledBuildItem, @@ -88,7 +87,8 @@ public DevServicesResultBuildItem startAmqpDevService( (launchMode.isTest() ? "(test) " : "") + "AMQP Dev Services Starting:", consoleInstalledBuildItem, loggingSetupBuildItem); try { - RunningDevService newDevService = startAmqpBroker(configuration, launchMode, devServicesConfig.timeout); + RunningDevService newDevService = startAmqpBroker(dockerStatusBuildItem, configuration, launchMode, + devServicesConfig.timeout); if (newDevService != null) { devService = newDevService; Map config = devService.getConfig(); @@ -146,8 +146,8 @@ private void shutdownBroker() { } } - private RunningDevService startAmqpBroker(AmqpDevServiceCfg config, LaunchModeBuildItem launchMode, - Optional timeout) { + private RunningDevService startAmqpBroker(DockerStatusBuildItem dockerStatusBuildItem, AmqpDevServiceCfg config, + LaunchModeBuildItem launchMode, Optional timeout) { if (!config.devServicesEnabled) { // explicitly disabled log.debug("Not starting Dev Services for AMQP, as it has been disabled in the config."); @@ -166,7 +166,7 @@ private RunningDevService startAmqpBroker(AmqpDevServiceCfg config, LaunchModeBu return null; } - if (!isDockerWorking.getAsBoolean()) { + if (!dockerStatusBuildItem.isDockerAvailable()) { log.warn("Docker isn't working, please configure the AMQP broker location."); return null; } diff --git a/extensions/smallrye-reactive-messaging-rabbitmq/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/rabbitmq/deployment/RabbitMQDevServicesProcessor.java b/extensions/smallrye-reactive-messaging-rabbitmq/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/rabbitmq/deployment/RabbitMQDevServicesProcessor.java index 1f527961a2d88..e2b73a49ceb09 100644 --- a/extensions/smallrye-reactive-messaging-rabbitmq/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/rabbitmq/deployment/RabbitMQDevServicesProcessor.java +++ b/extensions/smallrye-reactive-messaging-rabbitmq/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/rabbitmq/deployment/RabbitMQDevServicesProcessor.java @@ -21,11 +21,11 @@ import io.quarkus.bootstrap.classloading.QuarkusClassLoader; import io.quarkus.deployment.Feature; -import io.quarkus.deployment.IsDockerWorking; import io.quarkus.deployment.IsNormal; import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.deployment.builditem.DevServicesResultBuildItem; import io.quarkus.deployment.builditem.DevServicesResultBuildItem.RunningDevService; +import io.quarkus.deployment.builditem.DockerStatusBuildItem; import io.quarkus.deployment.builditem.LaunchModeBuildItem; import io.quarkus.deployment.console.ConsoleInstalledBuildItem; import io.quarkus.deployment.console.StartupLogCompressor; @@ -60,10 +60,9 @@ public class RabbitMQDevServicesProcessor { static volatile RabbitMQDevServiceCfg cfg; static volatile boolean first = true; - private final IsDockerWorking isDockerWorking = new IsDockerWorking(true); - @BuildStep(onlyIfNot = IsNormal.class, onlyIf = GlobalDevServicesConfig.Enabled.class) public DevServicesResultBuildItem startRabbitMQDevService( + DockerStatusBuildItem dockerStatusBuildItem, LaunchModeBuildItem launchMode, RabbitMQBuildTimeConfig rabbitmqClientBuildTimeConfig, Optional consoleInstalledBuildItem, @@ -85,7 +84,8 @@ public DevServicesResultBuildItem startRabbitMQDevService( (launchMode.isTest() ? "(test) " : "") + "RabbitMQ Dev Services Starting:", consoleInstalledBuildItem, loggingSetupBuildItem); try { - RunningDevService newDevService = startRabbitMQBroker(configuration, launchMode, devServicesConfig.timeout); + RunningDevService newDevService = startRabbitMQBroker(dockerStatusBuildItem, configuration, launchMode, + devServicesConfig.timeout); if (newDevService != null) { devService = newDevService; @@ -145,7 +145,8 @@ private void shutdownBroker() { } } - private RunningDevService startRabbitMQBroker(RabbitMQDevServiceCfg config, LaunchModeBuildItem launchMode, + private RunningDevService startRabbitMQBroker(DockerStatusBuildItem dockerStatusBuildItem, + RabbitMQDevServiceCfg config, LaunchModeBuildItem launchMode, Optional timeout) { if (!config.devServicesEnabled) { // explicitly disabled @@ -165,7 +166,7 @@ private RunningDevService startRabbitMQBroker(RabbitMQDevServiceCfg config, Laun return null; } - if (!isDockerWorking.getAsBoolean()) { + if (!dockerStatusBuildItem.isDockerAvailable()) { log.warn("Docker isn't working, please configure the RabbitMQ broker location."); return null; }