<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>io.vertx</groupId>
    <artifactId>vertx-stack</artifactId>
    <version>3.5.3</version>
  </parent>

  <artifactId>vertx-stack-docker</artifactId>
  <version>3.5.3</version>

  <name>Vert.x Stack - Docker images</name>
  <packaging>pom</packaging>

  <properties>
    <asciidoc.dir>${project.basedir}/src/main/asciidoc</asciidoc.dir>
    <docker.domain>vertx</docker.domain>
  </properties>

  <dependencies>
    <dependency>
      <groupId>io.vertx</groupId>
      <artifactId>vertx-stack-manager</artifactId>
      <version>3.5.3</version>
      <classifier>full</classifier>
      <type>zip</type>
    </dependency>
    <dependency>
      <groupId>com.jayway.restassured</groupId>
      <artifactId>rest-assured</artifactId>
      <version>2.9.0</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <profiles>

    <profile>
      <!-- Use -DskipDocker as the docker module requires docker to be installed, there are built an their own profile -->
      <id>docker</id>
      <activation>
        <property>
          <name>!skipDocker</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>io.fabric8</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <version>0.15.9</version>
            <executions>
              <execution>
                <id>build-images</id>
                <goals>
                  <goal>build</goal>
                </goals>
                <phase>package</phase>
              </execution>
              <execution>
                <id>start-containers</id>
                <goals>
                  <goal>start</goal>
                </goals>
                <phase>pre-integration-test</phase>
              </execution>
              <execution>
                <id>stop-containers</id>
                <goals>
                  <goal>stop</goal>
                </goals>
                <phase>post-integration-test</phase>
              </execution>
            </executions>

            <configuration>
              <images>
                <!-- Regular vert.x stack -->
                <image>
                  <alias>${docker.domain}/vertx3</alias>
                  <name>${docker.domain}/vertx3</name>
                  <build>
                    <tags>
                      <tag>latest</tag>
                      <tag>${project.version}</tag>
                    </tags>
                    <dockerFile>base/Dockerfile</dockerFile>
                  </build>
                  <run>
                    <namingStrategy>none</namingStrategy>
                    <volumes>
                      <bind>
                        <volume>${project.basedir}/src/test/it/:/verticles</volume>
                      </bind>
                    </volumes>
                    <ports>
                      <port>${vertx.host}:${vertx.port}:8080</port>
                    </ports>
                    <cmd>vertx run /verticles/MyVerticle.groovy</cmd>
                    <wait>
                      <log>Verticle startup - regular</log>
                      <http>
                        <url>http://${vertx.host}:${vertx.port}/</url>
                        <method>GET</method>
                        <status>200</status>
                      </http>
                      <time>30000</time>
                    </wait>
                    <log>
                      <enabled>true</enabled>
                      <color>red</color>
                    </log>
                  </run>
                </image>

                <image>
                  <alias>${docker.domain}/vertx3-alpine</alias>
                  <name>${docker.domain}/vertx3-alpine</name>
                  <build>
                    <tags>
                      <tag>latest</tag>
                      <tag>${project.version}</tag>
                    </tags>
                    <dockerFile>base-alpine/Dockerfile</dockerFile>
                  </build>
                  <run>
                    <namingStrategy>none</namingStrategy>
                    <volumes>
                      <bind>
                        <volume>${project.basedir}/src/test/it/:/verticles</volume>
                      </bind>
                    </volumes>
                    <ports>
                      <port>${vertx-alpine.host}:${vertx-alpine.port}:8080</port>
                    </ports>
                    <cmd>vertx run /verticles/MyVerticle.groovy</cmd>
                    <wait>
                      <log>Verticle startup - alpine</log>
                      <http>
                        <url>http://${vertx-alpine.host}:${vertx-alpine.port}/</url>
                        <method>GET</method>
                        <status>200</status>
                      </http>
                      <time>30000</time>
                    </wait>
                    <log>
                      <enabled>true</enabled>
                      <color>red</color>
                    </log>
                  </run>
                </image>

                <image>
                  <alias>${docker.domain}/vertx3-exec</alias>
                  <name>${docker.domain}/vertx3-exec</name>
                  <build>
                    <tags>
                      <tag>latest</tag>
                      <tag>${project.version}</tag>
                    </tags>
                    <dockerFile>exec/Dockerfile</dockerFile>
                  </build>
                  <run>
                    <namingStrategy>none</namingStrategy>
                    <volumes>
                      <bind>
                        <volume>${project.basedir}/src/test/it/:/verticles</volume>
                      </bind>
                    </volumes>
                    <ports>
                      <port>${vertx-exec.host}:${vertx-exec.port}:8080</port>
                    </ports>
                    <cmd>run /verticles/MyVerticle.groovy</cmd>
                    <wait>
                      <log>Verticle startup - exec-regular</log>
                      <http>
                        <url>http://${vertx-exec.host}:${vertx-exec.port}/</url>
                        <method>GET</method>
                        <status>200</status>
                      </http>
                      <time>30000</time>
                    </wait>
                    <log>
                      <enabled>true</enabled>
                      <color>red</color>
                    </log>
                  </run>
                </image>

                <image>
                  <alias>${docker.domain}/vertx3-exec-alpine</alias>
                  <name>${docker.domain}/vertx3-exec-alpine</name>
                  <build>
                    <tags>
                      <tag>latest</tag>
                      <tag>${project.version}</tag>
                    </tags>
                    <dockerFile>exec-alpine/Dockerfile</dockerFile>
                  </build>
                  <run>
                    <namingStrategy>none</namingStrategy>
                    <volumes>
                      <bind>
                        <volume>${project.basedir}/src/test/it/:/verticles</volume>
                      </bind>
                    </volumes>
                    <ports>
                      <port>${vertx-exec-alpine.host}:${vertx-exec-alpine.port}:8080</port>
                    </ports>
                    <cmd>run /verticles/MyVerticle.groovy</cmd>
                    <wait>
                      <log>Verticle startup - exec-alpine</log>
                      <http>
                        <url>http://${vertx-exec-alpine.host}:${vertx-exec-alpine.port}/</url>
                        <method>GET</method>
                        <status>200</status>
                      </http>
                      <time>30000</time>
                    </wait>
                    <log>
                      <enabled>true</enabled>
                      <color>red</color>
                    </log>
                  </run>
                </image>
              </images>
            </configuration>
          </plugin>

          <plugin>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.10</version>
            <executions>
              <execution>
                <id>unzip-vertx-stack</id>
                <phase>compile</phase>
                <goals>
                  <goal>unpack-dependencies</goal>
                </goals>
                <configuration>
                  <includeArtifactIds>vertx-stack-manager</includeArtifactIds>
                  <includeClassifiers>full</includeClassifiers>
                  <outputDirectory>${project.build.directory}/docker/${docker.domain}/vertx3/build</outputDirectory>
                  <markersDirectory>${project.build.directory}/marker-dependency</markersDirectory>
                </configuration>
              </execution>
              <execution>
                <id>unzip-vertx-stack-alpine</id>
                <phase>compile</phase>
                <goals>
                  <goal>unpack-dependencies</goal>
                </goals>
                <configuration>
                  <includeArtifactIds>vertx-stack-manager</includeArtifactIds>
                  <includeClassifiers>full</includeClassifiers>
                  <outputDirectory>${project.build.directory}/docker/${docker.domain}/vertx3-alpine/build
                  </outputDirectory>
                  <markersDirectory>${project.build.directory}/marker-dependency-alpine</markersDirectory>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.17</version>
            <executions>
              <execution>
                <id>failsafe-IT</id>
                <goals>
                  <goal>integration-test</goal>
                </goals>
                <phase>integration-test</phase>
              </execution>
              <execution>
                <id>failsafe-verify</id>
                <goals>
                  <goal>verify</goal>
                </goals>
                <phase>verify</phase>
              </execution>
            </executions>
            <configuration>
              <systemPropertyVariables>
                <vertx.url>http://${docker.host.address}:${vertx.port}</vertx.url>
                <vertx-exec.url>http://${docker.host.address}:${vertx-exec.port}</vertx-exec.url>
                <vertx-alpine.url>http://${docker.host.address}:${vertx-alpine.port}</vertx-alpine.url>
                <vertx-exec-alpine.url>http://${docker.host.address}:${vertx-exec-alpine.port}</vertx-exec-alpine.url>
                <vertx.version>${project.version}</vertx.version>
              </systemPropertyVariables>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <!-- Use -DskipDoc to avoid building doc -->
      <id>doc</id>
      <activation>
        <property>
          <name>!skipDoc</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.asciidoctor</groupId>
            <artifactId>asciidoctor-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>output-html</id>
                <phase>generate-resources</phase>
                <goals>
                  <goal>process-asciidoc</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
              <execution>
                <id>assemble</id>
                <phase>package</phase>
                <goals>
                  <goal>single</goal>
                </goals>
                <configuration>
                  <attach>true</attach>
                  <descriptors>
                    <descriptor>${basedir}/src/main/assembly/docs.xml</descriptor>
                  </descriptors>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <executions>
              <execution>
                <id>compile-IT</id>
                <goals>
                  <goal>testCompile</goal>
                </goals>
                <phase>test-compile</phase>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

</project>
