<?xml version="1.0" encoding="UTF-8"?>
<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>io.quarkiverse.quarkus-reactive-mysql-pool-client</groupId>
    <artifactId>quarkus-reactive-mysql-pool-client-parent</artifactId>
    <version>0.1.0</version>
  </parent>

  <artifactId>quarkus-reactive-mysql-pool-client-deployment</artifactId>
  <name>Quarkus Reactive Mysql Pool Client - Deployment</name>

  <properties>
    <reactive-mysql.url>vertx-reactive:mysql://localhost:3306/hibernate_orm_test</reactive-mysql.url>
  </properties>

  <dependencies>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-reactive-datasource-deployment</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-vertx-deployment</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-credentials-deployment</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkiverse.quarkus-reactive-mysql-pool-client</groupId>
      <artifactId>quarkus-reactive-mysql-pool-client</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-smallrye-health-spi</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-devservices-mysql</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-devservices-mariadb</artifactId>
    </dependency>

    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-resteasy-reactive-deployment</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.rest-assured</groupId>
      <artifactId>rest-assured</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-junit5-internal</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-smallrye-health-deployment</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.assertj</groupId>
      <artifactId>assertj-core</artifactId>
      <version>${assertj-core.version}</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <testResources>
      <testResource>
        <directory>src/test/resources</directory>
        <filtering>true</filtering>
      </testResource>
    </testResources>

    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <annotationProcessorPaths>
            <path>
              <groupId>io.quarkus</groupId>
              <artifactId>quarkus-extension-processor</artifactId>
              <version>${quarkus.version}</version>
            </path>
          </annotationProcessorPaths>
        </configuration>
      </plugin>

      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <skip>true</skip>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>test-mariadb</id>
      <activation>
        <property>
          <name>test-containers</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <skip>false</skip>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <id>docker-mariadb</id>
      <activation>
          <property>
              <name>start-containers</name>
          </property>
      </activation>
      <properties>
          <reactive-mysql.url>vertx-reactive:mysql://localhost:3308/hibernate_orm_test</reactive-mysql.url>
      </properties>
      <build>
          <plugins>
              <plugin>
                  <groupId>io.fabric8</groupId>
                  <artifactId>docker-maven-plugin</artifactId>
                  <configuration>
                      <images>
                          <image>
                              <!-- Be aware when testing healthcheck scripts, caching of named images can cause apparently non-deterministic behaviour.
                              Change the name if making changes. -->
                              <name>healthcheck-${mariadb.image}</name>
                              <alias>quarkus-test-mariadb</alias>
                              <build>
                                  <from>${mariadb.image}</from>
                                  <healthCheck>
                                      <!-- The exact values for these aren't very important, but it is important they are there -->
                                      <interval>5s</interval>
                                      <timeout>3s</timeout>
                                      <startPeriod>5s</startPeriod>
                                      <retries>5</retries>
                                      <!--     Note that mysqladmin ping returns 0 even if the password is wrong-->
                                      <cmd>
                                          <shell>mysqladmin ping -h localhost || exit 1</shell>
                                      </cmd>
                                  </healthCheck>
                              </build>
                              <run>
                                  <network>
                                      <mode>bridge</mode>
                                  </network>
                                  <ports>
                                      <port>3308:3306</port>
                                  </ports>
                                  <env>
                                      <MYSQL_USER>hibernate_orm_test</MYSQL_USER>
                                      <MYSQL_PASSWORD>hibernate_orm_test</MYSQL_PASSWORD>
                                      <MYSQL_DATABASE>hibernate_orm_test</MYSQL_DATABASE>
                                      <MYSQL_RANDOM_ROOT_PASSWORD>true</MYSQL_RANDOM_ROOT_PASSWORD>
                                  </env>
                                  <log>
                                      <prefix>MariaDB:</prefix>
                                      <date>default</date>
                                      <color>cyan</color>
                                  </log>
                                  <!-- Speed things up a bit by not actually flushing writes to disk -->
                                  <tmpfs>/var/lib/mysql</tmpfs>
                                  <wait>
                                      <!--   good docs found at: https://dmp.fabric8.io/#start-wait -->
                                      <!-- the sqladmin check seems more reliable than a tcp check, especially with
                                     diverse container runtimes -->
                                      <healthy>true</healthy>
                                      <!-- Unfortunately booting MariaDB is slow, needs to set a generous timeout: -->
                                      <time>40000</time>
                                  </wait>
                                  <volumes>
                                      <bind>
                                          <volume>
                                              ${project.basedir}/custom-mariadbconfig:/etc/mysql/conf.d${volume.access.modifier}
                                          </volume>
                                      </bind>
                                  </volumes>
                              </run>
                          </image>
                      </images>
                      <!--     Stops all mariadb images currently running, not just those we just started.
                           Useful to stop processes still running from a previously failed integration test run -->
                      <allContainers>true</allContainers>
                  </configuration>
                  <executions>
                      <execution>
                          <id>docker-start</id>
                          <phase>compile</phase>
                          <goals>
                              <goal>stop</goal>
                              <goal>build</goal>
                              <goal>start</goal>
                          </goals>
                      </execution>
                      <execution>
                          <id>docker-stop</id>
                          <phase>post-integration-test</phase>
                          <goals>
                              <goal>stop</goal>
                          </goals>
                      </execution>
                  </executions>
              </plugin>
              <plugin>
                  <groupId>org.codehaus.mojo</groupId>
                  <artifactId>exec-maven-plugin</artifactId>
                  <executions>
                      <execution>
                          <id>docker-prune</id>
                          <phase>generate-resources</phase>
                          <goals>
                              <goal>exec</goal>
                          </goals>
                          <configuration>
                              <executable>${docker-prune.location}</executable>
                          </configuration>
                      </execution>
                  </executions>
              </plugin>
          </plugins>
      </build>
    </profile>
  </profiles>
</project>
