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

Disable DevService if docker is not running #16959

Merged
merged 1 commit into from
May 4, 2021
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
@@ -1,5 +1,5 @@

package io.quarkus.container.image.docker.deployment;
package io.quarkus.deployment;

import java.io.BufferedReader;
import java.io.File;
Expand All @@ -13,9 +13,19 @@

import io.quarkus.deployment.util.ExecUtil;

public class DockerWorking implements BooleanSupplier {
public class IsDockerWorking implements BooleanSupplier {

private static final Logger LOGGER = Logger.getLogger(DockerWorking.class.getName());
private static final Logger LOGGER = Logger.getLogger(IsDockerWorking.class.getName());

private final boolean silent;

public IsDockerWorking() {
this(false);
}

public IsDockerWorking(boolean silent) {
this.silent = silent;
}

@Override
public boolean getAsBoolean() {
Expand All @@ -35,7 +45,9 @@ public boolean getAsBoolean() {
LOGGER.info("Docker daemon found. Version:" + filter.getOutput());
return true;
} else {
LOGGER.warn("Could not determine version of Docker daemon");
if (!silent) {
LOGGER.warn("Could not determine version of Docker daemon");
}
return false;
}
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import io.quarkus.container.spi.ContainerImageBuildRequestBuildItem;
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;
Expand All @@ -50,7 +51,7 @@ public class DockerProcessor {
private static final String DOCKER_DIRECTORY_NAME = "docker";
static final String DOCKER_CONTAINER_IMAGE_NAME = "docker";

private final DockerWorking dockerWorking = new DockerWorking();
private final IsDockerWorking isDockerWorking = new IsDockerWorking();

@BuildStep
public AvailableContainerImageExtensionBuildItem availability() {
Expand All @@ -75,7 +76,7 @@ public void dockerBuildFromJar(DockerConfig dockerConfig,
return;
}

if (!dockerWorking.getAsBoolean()) {
if (!isDockerWorking.getAsBoolean()) {
throw new RuntimeException("Unable to build docker image. Please check your docker installation");
}

Expand Down Expand Up @@ -107,7 +108,7 @@ public void dockerBuildFromNativeImage(DockerConfig dockerConfig,
return;
}

if (!dockerWorking.getAsBoolean()) {
if (!isDockerWorking.getAsBoolean()) {
throw new RuntimeException("Unable to build docker image. Please check your docker installation");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
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;
Expand All @@ -41,6 +42,8 @@ public class DevServicesDatasourceProcessor {

static volatile boolean first = true;

private final IsDockerWorking isDockerWorking = new IsDockerWorking(true);

@BuildStep(onlyIfNot = IsNormal.class)
DevServicesDatasourceResultBuildItem launchDatabases(CurateOutcomeBuildItem curateOutcomeBuildItem,
List<DefaultDataSourceDbKindBuildItem> installedDrivers,
Expand Down Expand Up @@ -182,6 +185,11 @@ private DevServicesDatasourceResultBuildItem.DbResult startDevDb(String dbName,
+ " as it has been disabled in the config");
return null;
}
if (!isDockerWorking.getAsBoolean()) {
log.warn("Please configure datasource URL for "
+ (dbName == null ? "default datasource" : dbName) + " or get a working docker instance");
return null;
}

Optional<String> defaultDbKind = DefaultDataSourceDbKindBuildItem.resolve(
dataSourceBuildTimeConfig.dbKind,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.testcontainers.utility.DockerImageName;

import io.quarkus.bootstrap.classloading.QuarkusClassLoader;
import io.quarkus.deployment.IsDockerWorking;
import io.quarkus.deployment.IsNormal;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
Expand All @@ -36,6 +37,8 @@ public class DevServicesMongoProcessor {
static volatile Map<String, CapturedProperties> capturedProperties;
static volatile boolean first = true;

private final IsDockerWorking isDockerWorking = new IsDockerWorking(true);

@BuildStep(onlyIfNot = IsNormal.class)
public DevServicesMongoResultBuildItem startMongo(List<MongoConnectionNameBuildItem> mongoConnections,
MongoClientBuildTimeConfig mongoClientBuildTimeConfig,
Expand Down Expand Up @@ -146,6 +149,13 @@ private StartResult startMongo(String connectionName, CapturedProperties capture
return null;
}

if (!isDockerWorking.getAsBoolean()) {
log.warn("Please configure datasource URL for "
+ (isDefault(connectionName) ? "default datasource" : connectionName)
+ " or get a working docker instance");
return null;
}

String configPrefix = getConfigPrefix(connectionName);

// TODO: do we need to check the hosts as well?
Expand Down