Search in sources :

Example 1 with ContainerAddress

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);
}
Also used : IsNormal(io.quarkus.deployment.IsNormal) ConfigUtils(io.quarkus.runtime.configuration.ConfigUtils) DockerImageName(org.testcontainers.utility.DockerImageName) DevServicesSharedNetworkBuildItem(io.quarkus.deployment.builditem.DevServicesSharedNetworkBuildItem) Logger(org.jboss.logging.Logger) TimeoutException(java.util.concurrent.TimeoutException) LaunchMode(io.quarkus.runtime.LaunchMode) HashMap(java.util.HashMap) RunningDevService(io.quarkus.deployment.builditem.DevServicesResultBuildItem.RunningDevService) ConsoleInstalledBuildItem(io.quarkus.deployment.console.ConsoleInstalledBuildItem) Supplier(java.util.function.Supplier) ConfigureUtil(io.quarkus.devservices.common.ConfigureUtil) AdminClient(org.apache.kafka.clients.admin.AdminClient) BuildStep(io.quarkus.deployment.annotations.BuildStep) CuratedApplicationShutdownBuildItem(io.quarkus.deployment.builditem.CuratedApplicationShutdownBuildItem) Duration(java.time.Duration) Map(java.util.Map) CreateTopicsResult(org.apache.kafka.clients.admin.CreateTopicsResult) LoggingSetupBuildItem(io.quarkus.deployment.logging.LoggingSetupBuildItem) DevServicesResultBuildItem(io.quarkus.deployment.builditem.DevServicesResultBuildItem) TopicDescription(org.apache.kafka.clients.admin.TopicDescription) KafkaAdminClient(org.apache.kafka.clients.admin.KafkaAdminClient) StartupLogCompressor(io.quarkus.deployment.console.StartupLogCompressor) ContainerAddress(io.quarkus.devservices.common.ContainerAddress) StrimziKafkaContainer(io.strimzi.test.container.StrimziKafkaContainer) AdminClientConfig(org.apache.kafka.clients.admin.AdminClientConfig) GlobalDevServicesConfig(io.quarkus.deployment.dev.devservices.GlobalDevServicesConfig) NewTopic(org.apache.kafka.clients.admin.NewTopic) Set(java.util.Set) ContainerLocator(io.quarkus.devservices.common.ContainerLocator) Config(org.eclipse.microprofile.config.Config) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Feature(io.quarkus.deployment.Feature) List(java.util.List) ConfigProvider(org.eclipse.microprofile.config.ConfigProvider) LaunchModeBuildItem(io.quarkus.deployment.builditem.LaunchModeBuildItem) Optional(java.util.Optional) DockerStatusBuildItem(io.quarkus.deployment.builditem.DockerStatusBuildItem) StrimziKafkaContainer(io.strimzi.test.container.StrimziKafkaContainer) RunningDevService(io.quarkus.deployment.builditem.DevServicesResultBuildItem.RunningDevService) ContainerAddress(io.quarkus.devservices.common.ContainerAddress)

Example 2 with ContainerAddress

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);
}
Also used : IsNormal(io.quarkus.deployment.IsNormal) Arrays(java.util.Arrays) BindMode(org.testcontainers.containers.BindMode) DockerImageName(org.testcontainers.utility.DockerImageName) DevServicesSharedNetworkBuildItem(io.quarkus.deployment.builditem.DevServicesSharedNetworkBuildItem) URL(java.net.URL) FileTime(java.nio.file.attribute.FileTime) RunningDevService(io.quarkus.deployment.builditem.DevServicesResultBuildItem.RunningDevService) ConsoleInstalledBuildItem(io.quarkus.deployment.console.ConsoleInstalledBuildItem) ConfigureUtil(io.quarkus.devservices.common.ConfigureUtil) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) ServerSocket(java.net.ServerSocket) OidcDevServicesBuildItem(io.quarkus.oidc.deployment.devservices.OidcDevServicesBuildItem) CuratedApplicationShutdownBuildItem(io.quarkus.deployment.builditem.CuratedApplicationShutdownBuildItem) Duration(java.time.Duration) Map(java.util.Map) LoggingSetupBuildItem(io.quarkus.deployment.logging.LoggingSetupBuildItem) CredentialRepresentation(org.keycloak.representations.idm.CredentialRepresentation) URI(java.net.URI) Path(java.nio.file.Path) StartupLogCompressor(io.quarkus.deployment.console.StartupLogCompressor) Predicate(java.util.function.Predicate) GlobalDevServicesConfig(io.quarkus.deployment.dev.devservices.GlobalDevServicesConfig) Set(java.util.Set) HttpHeaders(io.vertx.core.http.HttpHeaders) HttpResponse(io.vertx.mutiny.ext.web.client.HttpResponse) ContainerLocator(io.quarkus.devservices.common.ContainerLocator) Collectors(java.util.stream.Collectors) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) UncheckedIOException(java.io.UncheckedIOException) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) List(java.util.List) Buffer(io.vertx.mutiny.core.buffer.Buffer) ConfigProvider(org.eclipse.microprofile.config.ConfigProvider) OidcDevServicesUtils(io.quarkus.oidc.deployment.devservices.OidcDevServicesUtils) Optional(java.util.Optional) DockerStatusBuildItem(io.quarkus.deployment.builditem.DockerStatusBuildItem) ConfigUtils(io.quarkus.runtime.configuration.ConfigUtils) Logger(org.jboss.logging.Logger) LaunchMode(io.quarkus.runtime.LaunchMode) HashMap(java.util.HashMap) OptionalInt(java.util.OptionalInt) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Uni(io.smallrye.mutiny.Uni) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) BuildStep(io.quarkus.deployment.annotations.BuildStep) ConnectException(java.net.ConnectException) GenericContainer(org.testcontainers.containers.GenericContainer) DevServicesResultBuildItem(io.quarkus.deployment.builditem.DevServicesResultBuildItem) RoleRepresentation(org.keycloak.representations.idm.RoleRepresentation) IsEnabled(io.quarkus.oidc.deployment.OidcBuildStep.IsEnabled) Wait(org.testcontainers.containers.wait.strategy.Wait) RolesRepresentation(org.keycloak.representations.idm.RolesRepresentation) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) MalformedURLException(java.net.MalformedURLException) Files(java.nio.file.Files) ContainerAddress(io.quarkus.devservices.common.ContainerAddress) Vertx(io.vertx.core.Vertx) IOException(java.io.IOException) JsonSerialization(org.keycloak.util.JsonSerialization) Paths(java.nio.file.Paths) LaunchModeBuildItem(io.quarkus.deployment.builditem.LaunchModeBuildItem) WebClient(io.vertx.mutiny.ext.web.client.WebClient) InputStream(java.io.InputStream) DockerImageName(org.testcontainers.utility.DockerImageName) RunningDevService(io.quarkus.deployment.builditem.DevServicesResultBuildItem.RunningDevService) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ContainerAddress(io.quarkus.devservices.common.ContainerAddress)

Example 3 with ContainerAddress

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);
}
Also used : IsNormal(io.quarkus.deployment.IsNormal) ConfigUtils(io.quarkus.runtime.configuration.ConfigUtils) DockerImageName(org.testcontainers.utility.DockerImageName) DevServicesSharedNetworkBuildItem(io.quarkus.deployment.builditem.DevServicesSharedNetworkBuildItem) Logger(org.jboss.logging.Logger) HashMap(java.util.HashMap) ConsoleInstalledBuildItem(io.quarkus.deployment.console.ConsoleInstalledBuildItem) Supplier(java.util.function.Supplier) ConfigureUtil(io.quarkus.devservices.common.ConfigureUtil) HashSet(java.util.HashSet) BuildStep(io.quarkus.deployment.annotations.BuildStep) CuratedApplicationShutdownBuildItem(io.quarkus.deployment.builditem.CuratedApplicationShutdownBuildItem) BuildException(io.quarkus.builder.BuildException) Duration(java.time.Duration) Map(java.util.Map) LoggingSetupBuildItem(io.quarkus.deployment.logging.LoggingSetupBuildItem) DevServicesResultBuildItem(io.quarkus.deployment.builditem.DevServicesResultBuildItem) StartupLogCompressor(io.quarkus.deployment.console.StartupLogCompressor) ContainerAddress(io.quarkus.devservices.common.ContainerAddress) GlobalDevServicesConfig(io.quarkus.deployment.dev.devservices.GlobalDevServicesConfig) Set(java.util.Set) ContainerLocator(io.quarkus.devservices.common.ContainerLocator) Feature(io.quarkus.deployment.Feature) List(java.util.List) LaunchModeBuildItem(io.quarkus.deployment.builditem.LaunchModeBuildItem) Optional(java.util.Optional) ElasticsearchContainer(org.testcontainers.elasticsearch.ElasticsearchContainer) DockerStatusBuildItem(io.quarkus.deployment.builditem.DockerStatusBuildItem) Collections(java.util.Collections) DevServicesResultBuildItem(io.quarkus.deployment.builditem.DevServicesResultBuildItem) BuildException(io.quarkus.builder.BuildException) ContainerAddress(io.quarkus.devservices.common.ContainerAddress) ElasticsearchContainer(org.testcontainers.elasticsearch.ElasticsearchContainer)

Example 4 with ContainerAddress

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);
}
Also used : DotNames(io.quarkus.arc.processor.DotNames) DataIndexInMemoryContainer(org.kie.kogito.quarkus.processes.devservices.DataIndexInMemoryContainer) DockerImageName(org.testcontainers.utility.DockerImageName) DevServicesSharedNetworkBuildItem(io.quarkus.deployment.builditem.DevServicesSharedNetworkBuildItem) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) LoggerFactory(org.slf4j.LoggerFactory) SystemPropertyBuildItem(io.quarkus.deployment.builditem.SystemPropertyBuildItem) LaunchMode(io.quarkus.runtime.LaunchMode) ConsoleInstalledBuildItem(io.quarkus.deployment.console.ConsoleInstalledBuildItem) Supplier(java.util.function.Supplier) IsDevelopment(io.quarkus.deployment.IsDevelopment) IsDockerWorking(io.quarkus.deployment.IsDockerWorking) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) LATEST(org.kie.kogito.quarkus.processes.devservices.DataIndexInMemoryContainer.LATEST) BuildStep(io.quarkus.deployment.annotations.BuildStep) CuratedApplicationShutdownBuildItem(io.quarkus.deployment.builditem.CuratedApplicationShutdownBuildItem) AdditionalBeanBuildItem(io.quarkus.arc.deployment.AdditionalBeanBuildItem) LoggingSetupBuildItem(io.quarkus.deployment.logging.LoggingSetupBuildItem) DataIndexEventPublisher(org.kie.kogito.quarkus.processes.devservices.DataIndexEventPublisher) KOGITO_DATA_INDEX(org.kie.kogito.quarkus.processes.devservices.DataIndexEventPublisher.KOGITO_DATA_INDEX) KogitoDataIndexServiceAvailableBuildItem(org.kie.kogito.quarkus.common.deployment.KogitoDataIndexServiceAvailableBuildItem) Logger(org.slf4j.Logger) StartupLogCompressor(io.quarkus.deployment.console.StartupLogCompressor) ContainerAddress(io.quarkus.devservices.common.ContainerAddress) GlobalDevServicesConfig(io.quarkus.deployment.dev.devservices.GlobalDevServicesConfig) ArtifactVersion(org.apache.maven.artifact.versioning.ArtifactVersion) ContainerLocator(io.quarkus.devservices.common.ContainerLocator) Objects(java.util.Objects) List(java.util.List) LaunchModeBuildItem(io.quarkus.deployment.builditem.LaunchModeBuildItem) Closeable(java.io.Closeable) Optional(java.util.Optional) DevModeWorkflowLogger(org.kie.kogito.quarkus.processes.devservices.DevModeWorkflowLogger) DataIndexInMemoryContainer(org.kie.kogito.quarkus.processes.devservices.DataIndexInMemoryContainer) ContainerAddress(io.quarkus.devservices.common.ContainerAddress)

Example 5 with ContainerAddress

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);
}
Also used : Arrays(java.util.Arrays) DockerImageName(org.testcontainers.utility.DockerImageName) DevServicesSharedNetworkBuildItem(io.quarkus.deployment.builditem.DevServicesSharedNetworkBuildItem) LoggerFactory(org.slf4j.LoggerFactory) Container(com.github.dockerjava.api.model.Container) SystemPropertyBuildItem(io.quarkus.deployment.builditem.SystemPropertyBuildItem) LaunchMode(io.quarkus.runtime.LaunchMode) ConsoleInstalledBuildItem(io.quarkus.deployment.console.ConsoleInstalledBuildItem) Supplier(java.util.function.Supplier) IsDevelopment(io.quarkus.deployment.IsDevelopment) IsDockerWorking(io.quarkus.deployment.IsDockerWorking) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) BuildStep(io.quarkus.deployment.annotations.BuildStep) QuarkusDataSourcePassword(org.kie.kogito.tracing.decision.quarkus.deployment.DevServicesConfig.Property.QuarkusDataSourcePassword) CuratedApplicationShutdownBuildItem(io.quarkus.deployment.builditem.CuratedApplicationShutdownBuildItem) HibernateOrmDatabaseGeneration(org.kie.kogito.tracing.decision.quarkus.deployment.DevServicesConfig.Property.HibernateOrmDatabaseGeneration) QuarkusDataSourceDbKind(org.kie.kogito.tracing.decision.quarkus.deployment.DevServicesConfig.Property.QuarkusDataSourceDbKind) ContainerNetworkSettings(com.github.dockerjava.api.model.ContainerNetworkSettings) LoggingSetupBuildItem(io.quarkus.deployment.logging.LoggingSetupBuildItem) KafkaBootstrapServers(org.kie.kogito.tracing.decision.quarkus.deployment.DevServicesConfig.Property.KafkaBootstrapServers) TrustyServiceInMemoryContainer(org.kie.kogito.tracing.decision.quarkus.devservices.TrustyServiceInMemoryContainer) Logger(org.slf4j.Logger) StartupLogCompressor(io.quarkus.deployment.console.StartupLogCompressor) ContainerAddress(io.quarkus.devservices.common.ContainerAddress) TrustyServiceAvailableBuildItem(org.kie.kogito.quarkus.addons.common.deployment.TrustyServiceAvailableBuildItem) GlobalDevServicesConfig(io.quarkus.deployment.dev.devservices.GlobalDevServicesConfig) ContainerLocator(io.quarkus.devservices.common.ContainerLocator) Collectors(java.util.stream.Collectors) QuarkusDataSourceJdbcUrl(org.kie.kogito.tracing.decision.quarkus.deployment.DevServicesConfig.Property.QuarkusDataSourceJdbcUrl) QuarkusDataSourceUserName(org.kie.kogito.tracing.decision.quarkus.deployment.DevServicesConfig.Property.QuarkusDataSourceUserName) Objects(java.util.Objects) List(java.util.List) LaunchModeBuildItem(io.quarkus.deployment.builditem.LaunchModeBuildItem) Closeable(java.io.Closeable) Optional(java.util.Optional) ContainerPort(com.github.dockerjava.api.model.ContainerPort) DockerClientFactory(org.testcontainers.DockerClientFactory) KOGITO_TRUSTY_SERVICE(org.kie.kogito.tracing.decision.TrustyConstants.KOGITO_TRUSTY_SERVICE) ContainerNetwork(com.github.dockerjava.api.model.ContainerNetwork) TrustyServiceInMemoryContainer(org.kie.kogito.tracing.decision.quarkus.devservices.TrustyServiceInMemoryContainer) ContainerAddress(io.quarkus.devservices.common.ContainerAddress)

Aggregations

BuildStep (io.quarkus.deployment.annotations.BuildStep)5 CuratedApplicationShutdownBuildItem (io.quarkus.deployment.builditem.CuratedApplicationShutdownBuildItem)5 DevServicesSharedNetworkBuildItem (io.quarkus.deployment.builditem.DevServicesSharedNetworkBuildItem)5 LaunchModeBuildItem (io.quarkus.deployment.builditem.LaunchModeBuildItem)5 ConsoleInstalledBuildItem (io.quarkus.deployment.console.ConsoleInstalledBuildItem)5 StartupLogCompressor (io.quarkus.deployment.console.StartupLogCompressor)5 GlobalDevServicesConfig (io.quarkus.deployment.dev.devservices.GlobalDevServicesConfig)5 LoggingSetupBuildItem (io.quarkus.deployment.logging.LoggingSetupBuildItem)5 ContainerAddress (io.quarkus.devservices.common.ContainerAddress)5 ContainerLocator (io.quarkus.devservices.common.ContainerLocator)5 List (java.util.List)5 Optional (java.util.Optional)5 Supplier (java.util.function.Supplier)5 DockerImageName (org.testcontainers.utility.DockerImageName)5 LaunchMode (io.quarkus.runtime.LaunchMode)4 IsNormal (io.quarkus.deployment.IsNormal)3 BuildProducer (io.quarkus.deployment.annotations.BuildProducer)3 DevServicesResultBuildItem (io.quarkus.deployment.builditem.DevServicesResultBuildItem)3 DockerStatusBuildItem (io.quarkus.deployment.builditem.DockerStatusBuildItem)3 ConfigureUtil (io.quarkus.devservices.common.ConfigureUtil)3