use of io.quarkus.devservices.common.ContainerAddress in project quarkus by quarkusio.
the class DevServicesKafkaProcessor method startKafka.
private RunningDevService startKafka(DockerStatusBuildItem dockerStatusBuildItem, KafkaDevServiceCfg config, LaunchModeBuildItem launchMode, boolean useSharedNetwork, Optional<Duration> timeout) {
if (!config.devServicesEnabled) {
// explicitly disabled
log.debug("Not starting dev services for Kafka, as it has been disabled in the config.");
return null;
}
// Check if kafka.bootstrap.servers is set
if (ConfigUtils.isPropertyPresent(KAFKA_BOOTSTRAP_SERVERS)) {
log.debug("Not starting dev services for Kafka, the kafka.bootstrap.servers is configured.");
return null;
}
// Verify that we have kafka channels without bootstrap.servers
if (!hasKafkaChannelWithoutBootstrapServers()) {
log.debug("Not starting dev services for Kafka, all the channels are configured.");
return null;
}
if (!dockerStatusBuildItem.isDockerAvailable()) {
log.warn("Docker isn't working, please configure the Kafka bootstrap servers property (kafka.bootstrap.servers).");
return null;
}
final Optional<ContainerAddress> maybeContainerAddress = kafkaContainerLocator.locateContainer(config.serviceName, config.shared, launchMode.getLaunchMode());
// Starting the broker
final Supplier<RunningDevService> defaultKafkaBrokerSupplier = () -> {
if (config.imageName.contains("strimzi")) {
StrimziKafkaContainer container = new StrimziKafkaContainer(config.imageName).withBrokerId(1).withKraft().waitForRunning();
ConfigureUtil.configureSharedNetwork(container, "kafka");
if (config.serviceName != null) {
container.withLabel(DevServicesKafkaProcessor.DEV_SERVICE_LABEL, config.serviceName);
}
if (config.fixedExposedPort != 0) {
container.withPort(config.fixedExposedPort);
}
timeout.ifPresent(container::withStartupTimeout);
container.start();
return new RunningDevService(Feature.KAFKA_CLIENT.getName(), container.getContainerId(), container::close, KAFKA_BOOTSTRAP_SERVERS, container.getBootstrapServers());
} else {
RedPandaKafkaContainer container = new RedPandaKafkaContainer(DockerImageName.parse(config.imageName), config.fixedExposedPort, launchMode.getLaunchMode() == LaunchMode.DEVELOPMENT ? config.serviceName : null, useSharedNetwork, config.redpanda);
timeout.ifPresent(container::withStartupTimeout);
container.start();
return new RunningDevService(Feature.KAFKA_CLIENT.getName(), container.getContainerId(), container::close, KAFKA_BOOTSTRAP_SERVERS, container.getBootstrapServers());
}
};
return maybeContainerAddress.map(containerAddress -> new RunningDevService(Feature.KAFKA_CLIENT.getName(), containerAddress.getId(), null, KAFKA_BOOTSTRAP_SERVERS, containerAddress.getUrl())).orElseGet(defaultKafkaBrokerSupplier);
}
use of io.quarkus.devservices.common.ContainerAddress in project quarkus by quarkusio.
the class KeycloakDevServicesProcessor method startContainer.
private RunningDevService startContainer(DockerStatusBuildItem dockerStatusBuildItem, BuildProducer<KeycloakDevServicesConfigBuildItem> keycloakBuildItemBuildProducer, boolean useSharedNetwork, Optional<Duration> timeout) {
if (!capturedDevServicesConfiguration.enabled) {
// explicitly disabled
LOG.debug("Not starting Dev Services for Keycloak as it has been disabled in the config");
return null;
}
if (!isOidcTenantEnabled()) {
LOG.debug("Not starting Dev Services for Keycloak as 'quarkus.oidc.tenant.enabled' is false");
return null;
}
if (ConfigUtils.isPropertyPresent(AUTH_SERVER_URL_CONFIG_KEY)) {
LOG.debug("Not starting Dev Services for Keycloak as 'quarkus.oidc.auth-server-url' has been provided");
return null;
}
if (ConfigUtils.isPropertyPresent(PROVIDER_CONFIG_KEY)) {
LOG.debug("Not starting Dev Services for Keycloak as 'quarkus.oidc.provider' has been provided");
return null;
}
if (!dockerStatusBuildItem.isDockerAvailable()) {
LOG.warn("Please configure 'quarkus.oidc.auth-server-url' or get a working docker instance");
return null;
}
final Optional<ContainerAddress> maybeContainerAddress = keycloakDevModeContainerLocator.locateContainer(capturedDevServicesConfiguration.serviceName, capturedDevServicesConfiguration.shared, LaunchMode.current());
String imageName = capturedDevServicesConfiguration.imageName;
DockerImageName dockerImageName = DockerImageName.parse(imageName).asCompatibleSubstituteFor(imageName);
final Supplier<RunningDevService> defaultKeycloakContainerSupplier = () -> {
QuarkusOidcContainer oidcContainer = new QuarkusOidcContainer(dockerImageName, capturedDevServicesConfiguration.port, useSharedNetwork, capturedDevServicesConfiguration.realmPath, capturedDevServicesConfiguration.serviceName, capturedDevServicesConfiguration.shared, capturedDevServicesConfiguration.javaOpts);
timeout.ifPresent(oidcContainer::withStartupTimeout);
oidcContainer.start();
String internalUrl = startURL(oidcContainer.getHost(), oidcContainer.getPort(), oidcContainer.keycloakX);
String hostUrl = oidcContainer.useSharedNetwork ? startURL("localhost", oidcContainer.fixedExposedPort.getAsInt(), oidcContainer.keycloakX) : null;
Map<String, String> configs = prepareConfiguration(keycloakBuildItemBuildProducer, internalUrl, hostUrl, oidcContainer.realmRep, oidcContainer.keycloakX);
return new RunningDevService(KEYCLOAK_CONTAINER_NAME, oidcContainer.getContainerId(), oidcContainer::close, configs);
};
return maybeContainerAddress.map(containerAddress -> {
// TODO: this probably needs to be addressed
Map<String, String> configs = prepareConfiguration(keycloakBuildItemBuildProducer, getSharedContainerUrl(containerAddress), getSharedContainerUrl(containerAddress), null, false);
return new RunningDevService(KEYCLOAK_CONTAINER_NAME, containerAddress.getId(), null, configs);
}).orElseGet(defaultKeycloakContainerSupplier);
}
use of io.quarkus.devservices.common.ContainerAddress in project quarkus by quarkusio.
the class DevServicesElasticsearchProcessor method startElasticsearch.
private DevServicesResultBuildItem.RunningDevService startElasticsearch(DockerStatusBuildItem dockerStatusBuildItem, ElasticsearchDevServicesBuildTimeConfig config, DevservicesElasticsearchBuildItemsConfiguration buildItemConfig, LaunchModeBuildItem launchMode, boolean useSharedNetwork, Optional<Duration> timeout) throws BuildException {
if (!config.enabled.orElse(true)) {
// explicitly disabled
log.debug("Not starting dev services for Elasticsearch, as it has been disabled in the config.");
return null;
}
for (String hostsConfigProperty : buildItemConfig.hostsConfigProperties) {
// Check if elasticsearch hosts property is set
if (ConfigUtils.isPropertyPresent(hostsConfigProperty)) {
log.debugf("Not starting dev services for Elasticsearch, the %s property is configured.", hostsConfigProperty);
return null;
}
}
if (!dockerStatusBuildItem.isDockerAvailable()) {
log.warnf("Docker isn't working, please configure the Elasticsearch hosts property (%s).", displayProperties(buildItemConfig.hostsConfigProperties));
return null;
}
// We only support ELASTIC container for now
if (buildItemConfig.distribution == DevservicesElasticsearchBuildItem.Distribution.OPENSEARCH) {
throw new BuildException("Dev services for Elasticsearch didn't support Opensearch", Collections.emptyList());
}
// with the image we are about to launch
if (buildItemConfig.version != null) {
String containerTag = config.imageName.substring(config.imageName.indexOf(':') + 1);
if (!containerTag.startsWith(buildItemConfig.version)) {
throw new BuildException("Dev services for Elasticsearch detected a version mismatch, container image is " + config.imageName + " but the configured version is " + buildItemConfig.version + ". Either configure a different image or disable dev services for Elasticsearch.", Collections.emptyList());
}
}
final Optional<ContainerAddress> maybeContainerAddress = elasticsearchContainerLocator.locateContainer(config.serviceName, config.shared, launchMode.getLaunchMode());
// Starting the server
final Supplier<DevServicesResultBuildItem.RunningDevService> defaultElasticsearchSupplier = () -> {
ElasticsearchContainer container = new ElasticsearchContainer(DockerImageName.parse(config.imageName));
ConfigureUtil.configureSharedNetwork(container, "elasticsearch");
if (config.serviceName != null) {
container.withLabel(DEV_SERVICE_LABEL, config.serviceName);
}
if (config.port.isPresent()) {
container.setPortBindings(List.of(config.port.get() + ":" + config.port.get()));
}
timeout.ifPresent(container::withStartupTimeout);
container.addEnv("ES_JAVA_OPTS", config.javaOpts);
// Disable security as else we would need to configure it correctly to avoid tons of WARNING in the log
container.addEnv("xpack.security.enabled", "false");
container.start();
return new DevServicesResultBuildItem.RunningDevService(Feature.ELASTICSEARCH_REST_CLIENT_COMMON.getName(), container.getContainerId(), container::close, buildPropertiesMap(buildItemConfig, container.getHttpHostAddress()));
};
return maybeContainerAddress.map(containerAddress -> new DevServicesResultBuildItem.RunningDevService(Feature.ELASTICSEARCH_REST_CLIENT_COMMON.getName(), containerAddress.getId(), null, buildPropertiesMap(buildItemConfig, containerAddress.getUrl()))).orElseGet(defaultElasticsearchSupplier);
}
use of io.quarkus.devservices.common.ContainerAddress in project kogito-runtimes by kiegroup.
the class KogitoDevServicesProcessor method startDataIndex.
private DataIndexInstance startDataIndex(DataIndexDevServiceConfig config, LaunchModeBuildItem launchMode, boolean useSharedNetwork) {
if (!config.devServicesEnabled) {
// explicitly disabled
LOGGER.debug("Not starting dev services for Kogito, as it has been disabled in the config.");
return null;
}
if (!isDockerWorking.getAsBoolean()) {
LOGGER.warn("Docker isn't working, unable to start Data Index image.");
return null;
}
final Optional<ContainerAddress> maybeContainerAddress = LOCATOR.locateContainer(config.serviceName, config.shared, launchMode.getLaunchMode());
// Starting Data Index
final Supplier<DataIndexInstance> dataIndexSupplier = () -> {
try {
DataIndexInMemoryContainer container = new DataIndexInMemoryContainer(DockerImageName.parse(config.imageName), config.fixedExposedPort, launchMode.getLaunchMode() == LaunchMode.DEVELOPMENT ? config.serviceName : null, useSharedNetwork);
container.start();
return new DataIndexInstance(container.getUrl(), container::close);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
};
return maybeContainerAddress.map(containerAddress -> new DataIndexInstance(containerAddress.getUrl(), null)).orElseGet(dataIndexSupplier);
}
use of io.quarkus.devservices.common.ContainerAddress in project kogito-runtimes by kiegroup.
the class KogitoDevServicesProcessor method startTrustyService.
private TrustyServiceInstance startTrustyService(final TrustyServiceDevServiceConfig config, final DevServicesConfig devServicesConfig, final LaunchModeBuildItem launchMode, final boolean useSharedNetwork) {
if (!config.devServicesEnabled) {
// explicitly disabled
LOGGER.info("Not starting DevServices for Kogito, as it has been disabled in the config.");
return null;
}
if (!isDockerWorking.getAsBoolean()) {
LOGGER.warn("Docker isn't working, unable to start TrustyService image.");
return null;
}
final Optional<ContainerAddress> maybeContainerAddress = LOCATOR.locateContainer(config.serviceName, config.shared, launchMode.getLaunchMode());
// Starting TrustyService
final Supplier<TrustyServiceInstance> trustyServiceSupplier = () -> {
try {
TrustyServiceInMemoryContainer container = new TrustyServiceInMemoryContainer(DockerImageName.parse(config.imageName), config.fixedExposedPort, launchMode.getLaunchMode() == LaunchMode.DEVELOPMENT ? config.serviceName : null, useSharedNetwork);
LOGGER.debug(String.format("TrustyService DataSource Kind: %s", devServicesConfig.getDataSourceKind()));
LOGGER.debug(String.format("TrustyService DataSource Username: %s", devServicesConfig.getDataSourceUserName()));
LOGGER.debug(String.format("TrustyService DataSource Password: %s", devServicesConfig.getDataSourcePassword()));
LOGGER.debug(String.format("TrustyService DataSource URL: %s", devServicesConfig.getDataSourceUrl()));
LOGGER.debug(String.format("TrustyService Kafka Bootstrap Server: %s", devServicesConfig.getKafkaBootstrapServer()));
LOGGER.debug(String.format("TrustyService Hibernate ORM Database Generation: %s", devServicesConfig.getHibernateOrmDatabaseGeneration()));
// Environment variables used by kogito-images when launching the TrustyService container
container.addEnv("SCRIPT_DEBUG", "false");
container.addEnv("EXPLAINABILITY_ENABLED", "false");
// Environment variables used by TrustyService to integrate with other services
container.addEnv(QuarkusDataSourceDbKind.getEnvironmentVariableName(), devServicesConfig.getDataSourceKind());
container.addEnv(QuarkusDataSourceUserName.getEnvironmentVariableName(), devServicesConfig.getDataSourceUserName());
container.addEnv(QuarkusDataSourcePassword.getEnvironmentVariableName(), devServicesConfig.getDataSourcePassword());
container.addEnv(QuarkusDataSourceJdbcUrl.getEnvironmentVariableName(), devServicesConfig.getDataSourceUrl());
container.addEnv(KafkaBootstrapServers.getEnvironmentVariableName(), devServicesConfig.getKafkaBootstrapServer());
container.addEnv(HibernateOrmDatabaseGeneration.getEnvironmentVariableName(), devServicesConfig.getHibernateOrmDatabaseGeneration());
container.start();
return new TrustyServiceInstance(container.getUrl(), container::close);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
};
return maybeContainerAddress.map(containerAddress -> new TrustyServiceInstance(containerAddress.getUrl(), null)).orElseGet(trustyServiceSupplier);
}
Aggregations