<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>
  <name>== GreenMail Docker :: Standalone ==</name>
  <description>Docker image running GreenMail Standalone</description>

  <artifactId>greenmail-docker-standalone</artifactId>
  <version>2.1.9</version>
  <!-- Does not actually provide a JAR, but requires the JAR Maven lifecycle
       for unit test -->
  <packaging>jar</packaging>

  <properties>
    <greenmail.docker.tags>${project.version}</greenmail.docker.tags>
  </properties>

  <parent>
    <groupId>com.icegreen</groupId>
    <artifactId>greenmail-parent</artifactId>
    <version>2.1.9</version>
    <relativePath>../../pom.xml</relativePath>
  </parent>

  <dependencies>
    <dependency>
      <groupId>com.icegreen</groupId>
      <artifactId>greenmail</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-api</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-core</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-slf4j-impl</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.assertj</groupId>
      <artifactId>assertj-core</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>jakarta.ws.rs</groupId>
      <artifactId>jakarta.ws.rs-api</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.glassfish.jersey.core</groupId>
      <artifactId>jersey-client</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.glassfish.jersey.inject</groupId>
      <artifactId>jersey-hk2</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <configuration>
          <artifactItems>
            <artifactItem>
              <groupId>com.icegreen</groupId>
              <artifactId>greenmail-standalone</artifactId>
              <version>${project.version}</version>
              <type>jar</type>
              <overWrite>false</overWrite>
              <destFileName>greenmail-standalone.jar</destFileName>
              <includes>greenmail.p12</includes>
            </artifactItem>
          </artifactItems>
          <outputDirectory>${project.build.directory}</outputDirectory>
        </configuration>
        <executions>
          <execution>
            <phase>initialize</phase>
            <goals>
              <goal>copy</goal>
              <goal>unpack</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>io.fabric8</groupId>
        <artifactId>docker-maven-plugin</artifactId>
        <configuration>
          <autoPull>true</autoPull>
          <verbose>true</verbose>
          <images>
            <image>
              <name>greenmail/standalone:${project.version}</name>
              <build>
                <tags>${greenmail.docker.tags}</tags>
                <contextDir>${basedir}</contextDir>
                <buildx>
                  <platforms>
                    <platform>linux/amd64</platform>
                    <platform>linux/arm64</platform>
                  </platforms>
                </buildx>
              </build>
              <run>
                <ports>
                  <port>3025:3025</port>
                  <port>3110:3110</port>
                  <port>3143:3143</port>
                  <port>3465:3465</port>
                  <port>3993:3993</port>
                  <port>3995:3995</port>
                  <port>8080:8080</port>
                </ports>
                <wait>
                  <tcp>
                    <mode>mapped</mode>
                    <host>${docker.host.address}</host>
                    <ports>
                      <port>3025</port>
                      <port>3110</port>
                      <port>3143</port>
                      <port>3465</port>
                      <port>3993</port>
                      <port>3995</port>
                      <port>8080</port>
                    </ports>
                  </tcp>
                  <time>10000</time>
                </wait>
                <containerNamePattern>${project.artifactId}-%i</containerNamePattern>
              </run>
            </image>
          </images>
          <verbose>true</verbose>
        </configuration>
        <executions>
          <execution>
            <id>docker-package</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>build</goal>
            </goals>
          </execution>
          <execution>
            <id>docker-deploy</id>
            <phase>deploy</phase>
            <goals>
              <goal>push</goal>
            </goals>
          </execution>
          <execution>
            <id>docker-it-start</id>
            <phase>pre-integration-test</phase>
            <goals>
              <goal>start</goal>
            </goals>
          </execution>
          <execution>
            <id>docker-it-stop</id>
            <phase>post-integration-test</phase>
            <goals>
              <goal>stop</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <!-- Tell surefire to skip test, there is none -->
      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <skip>true</skip>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-failsafe-plugin</artifactId>
        <configuration>
          <systemPropertyVariables>
            <greenmail.host.address>${docker.host.address}</greenmail.host.address>
          </systemPropertyVariables>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>docker-tag-latest</id>
      <!-- Use if you want to tag docker image with version and 'latest' label -->
      <properties>
        <greenmail.docker.tags>${project.version},latest</greenmail.docker.tags>
      </properties>
    </profile>
  </profiles>

</project>
