<?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>
    <artifactId>atlassian-bamboo-tests-parent</artifactId>
    <groupId>com.atlassian.bamboo</groupId>
    <version>9.3.0-m030</version>
  </parent>
  <artifactId>bamboo-docker-images-tests</artifactId>
  <name>Atlassian Bamboo Docker Images Tests Module</name>

  <properties>
    <bamboo.test.version>${project.version}</bamboo.test.version>
    <data.directory>${project.basedir}/test-data</data.directory>

    <bamboo.server.image>bamboo-server-image</bamboo.server.image>
    <!-- Server name is also server's container's host name. If you want to change it you need to recreate server's home -->
    <bamboo.server.name>bamboo-server</bamboo.server.name>
    <bamboo.server.port>6990</bamboo.server.port>
    <bamboo.server.home>home-6.10.2</bamboo.server.home>

    <bamboo.agent.image>bamboo-agent-image</bamboo.agent.image>
    <bamboo.agent.name>bamboo-agent</bamboo.agent.name>

    <bamboo.network>bamboo-network</bamboo.network>
    <bamboo.in.docker.version>${project.version}</bamboo.in.docker.version>
  </properties>

  <dependencies>
    <!-- Bamboo dependencies -->
    <dependency>
      <groupId>com.atlassian.bamboo</groupId>
      <artifactId>atlassian-bamboo-pageobjects</artifactId>
      <scope>test</scope>
    </dependency>

    <!-- 3rd party dependencies -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <profiles>
    <profile>
      <id>docker-images-tests</id>
      <build>
        <plugins>

          <plugin>
            <groupId>io.fabric8</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <configuration>
              <logDate>NONE</logDate>
              <imagePullPolicy>Never</imagePullPolicy>
              <verbose>true</verbose>
              <images>
                <image>
                  <alias>${bamboo.server.name}</alias>
                  <name>${bamboo.server.image}</name>
                  <run>
                    <env>
                      <ATL_TOMCAT_PORT>6990</ATL_TOMCAT_PORT>
                      <ATL_TOMCAT_CONTEXTPATH>/bamboo</ATL_TOMCAT_CONTEXTPATH>
                      <BUILD_NUMBER>80000</BUILD_NUMBER> <!--lowest build number supported by "new" Docker structure-->
                    </env>
                    <ports>
                      <port>${bamboo.server.port}:${bamboo.server.port}</port>
                    </ports>
                    <volumes>
                      <bind>
                        <volume>${data.directory}/docker/${bamboo.server.home}:/var/atlassian/application-data/bamboo</volume>
                      </bind>
                    </volumes>
                    <network>
                      <mode>custom</mode>
                      <name>${bamboo.network}</name>
                      <alias>${bamboo.server.name}</alias>
                    </network>
                    <wait>
                      <log>org.apache.catalina.startup.Catalina.start Server startup in</log>
                      <time>600000</time>
                    </wait>
                    <log>
                      <enabled>true</enabled>
                      <date>NONE</date>
                      <color>blue</color>
                      <prefix xml:space="preserve">%n> </prefix>
                    </log>
                  </run>
                </image>

                <image>
                  <alias>${bamboo.agent.name}</alias>
                  <name>${bamboo.agent.image}</name>
                  <run>
                    <env>
                      <BAMBOO_SERVER>http://${bamboo.server.name}:${bamboo.server.port}/bamboo</BAMBOO_SERVER>
                    </env>
                    <network>
                      <mode>custom</mode>
                      <name>${bamboo.network}</name>
                      <alias>${bamboo.agent.name}</alias>
                    </network>
                    <dependsOn>
                      <container>${bamboo.server.name}</container>
                    </dependsOn>
                    <wait>
                      <log>ready to receive builds.</log>
                      <time>600000</time>
                    </wait>
                    <log>
                      <enabled>true</enabled>
                      <date>NONE</date>
                      <color>green</color>
                      <prefix xml:space="preserve">%n> </prefix>
                    </log>
                  </run>
                </image>
              </images>
            </configuration>
            <executions>
              <execution>
                <id>start-containers</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>start</goal>
                </goals>
              </execution>
              <execution>
                <id>stop-containers</id>
                <phase>post-integration-test</phase>
                <goals>
                  <goal>stop</goal>
                </goals>
              </execution>
              <execution>
                <id>clean-containers</id>
                <phase>clean</phase>
                <goals>
                  <goal>stop</goal>
                  <goal>remove</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <configuration>
              <parallel>none</parallel>
              <includes>
                <include>it/**/*Test.java</include>
              </includes>
            </configuration>
            <executions>
              <execution>
                <goals>
                  <goal>integration-test</goal>
                  <goal>verify</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

        </plugins>
      </build>
    </profile>
  </profiles>


</project>
