<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.kie.kogito</groupId>
        <artifactId>apps-integration-tests</artifactId>
        <version>1.20.0.Final</version>
    </parent>

    <artifactId>integration-tests-trusty-audit</artifactId>
    <name>Kogito Apps :: Integration Tests :: Trusty Audit UI</name>
    <packaging>pom</packaging>

    <properties>
        <container.image.kogito-service>to-be-changed-in-submodules</container.image.kogito-service>
        <version.dmp.fabric8>0.38.1</version.dmp.fabric8>
    </properties>

    <dependencies>
        <!-- ensure dependent modules were built, but not added in the classpath -->
        <dependency>
            <groupId>org.kie.kogito</groupId>
            <artifactId>explainability-service-messaging</artifactId>
            <version>${project.version}</version>
            <type>pom</type>
            <scope>provided</scope>
            <exclusions>
                <exclusion>
                    <groupId>*</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.kie.kogito</groupId>
            <artifactId>integration-tests-trusty-service-quarkus</artifactId>
            <version>${project.version}</version>
            <type>pom</type>
            <scope>provided</scope>
            <exclusions>
                <exclusion>
                    <groupId>*</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.kie.kogito</groupId>
            <artifactId>trusty-service-infinispan</artifactId>
            <version>${project.version}</version>
            <type>pom</type>
            <scope>provided</scope>
            <exclusions>
                <exclusion>
                    <groupId>*</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.kie.kogito</groupId>
            <artifactId>trusty-ui</artifactId>
            <version>${project.version}</version>
            <type>pom</type>
            <scope>provided</scope>
            <exclusions>
                <exclusion>
                    <groupId>*</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>com.github.eirslett</groupId>
                <artifactId>frontend-maven-plugin</artifactId>
                <version>${version.frontend.plugin}</version>
                <configuration>
                    <workingDirectory>${project.root.dir}/ui-packages</workingDirectory>
                </configuration>

                <executions>
                    <!--
                        This module depends on the 'trusty-ui' which depends on 'kogito-apps-ui-packages' module.
                        Please consider addition of executions from 'frontend-maven-plugin' in 
                        the 'kogito-apps-ui-packages' module in case that this dependency will be removed.
                    !-->        
                    <execution>
                        <id>yarn e2e test</id>
                        <goals>
                            <goal>yarn</goal>
                        </goals>
                        <phase>integration-test</phase>
                        <configuration>
                            <skip>${skip.ui.build}</skip>
                            <arguments>run test:e2e:trusty</arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>io.fabric8</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>${version.dmp.fabric8}</version>
                <configuration>
                    <autoCreateCustomNetworks>true</autoCreateCustomNetworks>
                    <images>
                        <image>
                            <alias>zookeeper</alias>
                            <name>wurstmeister/zookeeper:latest</name>
                              
                            <run>
                                <ports>
                                    <port>2181:2181</port>
                                </ports>
                                <env>
                                    <LOG_DIR>/tmp/logs</LOG_DIR>
                                </env>
                                <network>
                                    <mode>custom</mode>
                                    <name>trusty-nw</name>
                                </network>
                                <log>
                                    <prefix>%a </prefix>
                                    <file>${project.build.directory}/zookeeper.log</file>
                                </log>
                            </run>
                        </image>
                        <image>
                            <alias>kafka</alias>
                            <name>${container.image.wurstmeister.kafka}</name>

                            <run>
                                <dependsOn>
                                    <container>zookeeper</container>
                                </dependsOn>
                              <ports>
                                    <port>9092:9092</port>
                                    <!-- This plugin does not suport the expose port ("9093") !-->
                                    <port>9093:9093</port>
                                </ports>
                                <env>
                                    <LOG_DIR>/tmp/logs</LOG_DIR>
                                    <KAFKA_ADVERTISED_LISTENERS>INSIDE://kafka-1:9093,OUTSIDE://localhost:9092</KAFKA_ADVERTISED_LISTENERS>
                                    <KAFKA_LISTENER_SECURITY_PROTOCOL_MAP>INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT</KAFKA_LISTENER_SECURITY_PROTOCOL_MAP> 
                                    <KAFKA_LISTENERS>INSIDE://0.0.0.0:9093,OUTSIDE://0.0.0.0:9092</KAFKA_LISTENERS>
                                    <KAFKA_ZOOKEEPER_CONNECT>zookeeper-1:2181</KAFKA_ZOOKEEPER_CONNECT>
                                    <KAFKA_INTER_BROKER_LISTENER_NAME>INSIDE</KAFKA_INTER_BROKER_LISTENER_NAME>
                                </env>
                                <network>
                                    <mode>custom</mode>
                                    <name>trusty-nw</name>
                                </network>
                                <log>
                                    <prefix>%a </prefix>
                                    <file>${project.build.directory}/kafka.log</file>
                                </log>
                            </run>
                        </image>
                        <image>
                            <alias>infinispan</alias>
                            <name>${container.image.infinispan}</name>

                            <run>
                                <ports>
                                    <port>11222:11222</port>
                                </ports>
                                <cmd>-c infinispan-demo.xml</cmd>
                                <network>
                                    <mode>custom</mode>
                                    <name>trusty-nw</name>
                                </network>
                                <volumes>
                                    <bind>
                                        <volume>./src/test/resources/infinispan/infinispan.xml:/opt/infinispan/server/conf/infinispan-demo.xml:z</volume>
                                    </bind>
                                </volumes>
                                <log>
                                  <prefix>%a </prefix>
                                  <file>${project.build.directory}/infinispan.log</file>
                                </log>
                                <wait>
                                    <time>60000</time>
                                    <tcp>
                                        <ports>
                                            <port>11222</port>
                                        </ports>
                                    </tcp>
                                </wait>
                            </run>
                        </image>
                        <image>
                          <alias>kogito-app</alias>
                            <name>${container.image.integration-tests-trusty-service-quarkus}</name>

                            <run>
                                <dependsOn>
                                    <container>kafka</container>
                                </dependsOn>
                                <ports>
                                    <port>8080:8080</port>
                                </ports>
                                <env>
                                    <KAFKA_BOOTSTRAP_SERVERS>kafka-1:9093</KAFKA_BOOTSTRAP_SERVERS>
                                    <KOGITO_SERVICE_URL>http://integration-tests-trusty-service-quarkus-1:8080</KOGITO_SERVICE_URL>
                                </env>
                                <network>
                                    <mode>custom</mode>
                                    <name>trusty-nw</name>
                                </network>
                                <log>
                                    <prefix>%a </prefix>
                                    <file>${project.build.directory}/kogito-app.log</file>
                                </log>
                            </run>
                        </image>
                        <image>
                            <alias>explainability</alias>
                            <name>${container.image.explainability-service-messaging}</name>

                            <run>
                                <dependsOn>
                                    <container>kafka</container>
                                    <container>kogito-app</container>
                                </dependsOn>
                                <ports>
                                    <port>1336:8080</port>
                                </ports>
                                <env>
                                    <KAFKA_BOOTSTRAP_SERVERS>kafka-1:9093</KAFKA_BOOTSTRAP_SERVERS>
                                </env>
                                <network>
                                    <mode>custom</mode>
                                    <name>trusty-nw</name>
                                </network>
                                <log>
                                    <prefix>%a </prefix>
                                    <file>${project.build.directory}/explainability.log</file>
                                </log>
                                <wait>
                                    <time>60000</time>
                                    <tcp>
                                        <ports>
                                            <port>8080</port>
                                        </ports>
                                    </tcp>
                                </wait>
                            </run>
                        </image>
                        <image>
                            <alias>trusty</alias>
                            <name>${container.image.trusty-service-infinispan}</name>

                            <run>
                                <dependsOn>
                                    <container>kafka</container>
                                    <container>infinispan</container>
                                </dependsOn>
                                <ports>
                                    <port>1337:8080</port>
                                </ports>
                                <env>
                                    <KAFKA_BOOTSTRAP_SERVERS>kafka-1:9093</KAFKA_BOOTSTRAP_SERVERS>
                                    <QUARKUS_INFINISPAN_CLIENT_SERVER_LIST>server-1:11222</QUARKUS_INFINISPAN_CLIENT_SERVER_LIST>
                                    <QUARKUS_INFINISPAN_CLIENT_USE_AUTH>"false"</QUARKUS_INFINISPAN_CLIENT_USE_AUTH>
                                    <TRUSTY_EXPLAINABILITY_ENABLED>"true"</TRUSTY_EXPLAINABILITY_ENABLED>
                                </env>
                                <network>
                                    <mode>custom</mode>
                                    <name>trusty-nw</name>
                                </network>
                                <log>
                                    <prefix>%a </prefix>
                                    <file>${project.build.directory}/trusty.log</file>
                                </log>
                            </run>
                        </image>
                        <image>
                            <alias>trusty-ui</alias>
                            <name>${container.image.trusty-ui}</name>

                            <run>
                                <dependsOn>
                                    <container>kafka</container>
                                </dependsOn>
                                <ports>
                                    <port>1338:8080</port>
                                </ports>
                                <env>
                                    <KOGITO_TRUSTY_HTTP_URL>http://localhost:1337</KOGITO_TRUSTY_HTTP_URL>
                                </env>
                                <network>
                                    <mode>custom</mode>
                                    <name>trusty-nw</name>
                                </network>
                                <log>
                                    <prefix>%a </prefix>
                                    <file>${project.build.directory}/trusty-ui.log</file>
                                </log>
                                <wait>
                                    <time>60000</time>
                                    <tcp>
                                        <ports>
                                            <port>8080</port>
                                        </ports>
                                    </tcp>
                                </wait>
                            </run>
                        </image>
                    </images>
                </configuration>
                <executions>
                    <execution>
                        <id>start</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>stop</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>