<?xml version="1.0" encoding="UTF-8"?>
<!--

     Copyright 2017-2022 Adobe.

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

             http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.

-->
<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>com.adobe.testing</groupId>
    <artifactId>s3mock-parent</artifactId>
    <version>2.11.0</version>
  </parent>

  <artifactId>s3mock-docker</artifactId>
  <packaging>pom</packaging>

  <name>S3Mock - Docker</name>

  <dependencies>
    <dependency>
      <groupId>com.adobe.testing</groupId>
      <artifactId>s3mock</artifactId>
      <classifier>exec</classifier>
    </dependency>
  </dependencies>

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>io.fabric8</groupId>
          <artifactId>docker-maven-plugin</artifactId>
          <configuration combine.self="override">
            <verbose>true</verbose>
            <images>
              <image>
                <alias>s3mock</alias>
                <name>${docker.image.name}</name>
                <build>
                  <dockerFile>${project.basedir}/Dockerfile</dockerFile>
                  <tags>
                    <tag>${project.version}</tag>
                    <tag>latest</tag>
                  </tags>
                </build>
              </image>
            </images>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <plugin>
        <artifactId>maven-checkstyle-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>3.4.0</version>
        <configuration>
          <artifactItems>
            <artifactItem>
              <groupId>com.adobe.testing</groupId>
              <artifactId>s3mock</artifactId>
              <classifier>exec</classifier>
              <type>jar</type>
              <overWrite>false</overWrite>
              <outputDirectory>${project.build.directory}</outputDirectory>
              <destFileName>s3mock-exec.jar</destFileName>
            </artifactItem>
          </artifactItems>
          <overWriteSnapshots>true</overWriteSnapshots>
        </configuration>
        <executions>
          <execution>
            <id>copy</id>
            <goals>
              <goal>copy</goal>
            </goals>
            <phase>prepare-package</phase>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>build-docker-image</id>
      <activation>
        <property>
          <!-- If running with -DskipDocker, this profile won't be active. -->
          <name>!skipDocker</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <configuration>
              <includeProjectDependencies>true</includeProjectDependencies>
              <includePluginDependencies>false</includePluginDependencies>
            </configuration>
            <dependencies>
              <dependency>
                <groupId>com.adobe.testing</groupId>
                <artifactId>s3mock</artifactId>
                <version>${project.version}</version>
                <classifier>exec</classifier>
                <type>jar</type>
              </dependency>
            </dependencies>
            <executions>
              <execution>
                <id>start-buildkit</id>
                <goals>
                  <goal>exec</goal>
                </goals>
                <phase>prepare-package</phase>
                <configuration>
                  <executable>sh</executable>
                  <arguments>
                    <argument>start-buildkit.sh</argument>
                    <argument>${docker-builder.image.name}</argument>
                  </arguments>
                </configuration>
              </execution>
              <execution>
                <id>build-docker-image</id>
                <goals>
                  <goal>exec</goal>
                </goals>
                <phase>package</phase>
                <configuration>
                  <executable>sh</executable>
                  <arguments>
                    <argument>build-docker-image.sh</argument>
                    <argument>${docker-builder.image.name}</argument>
                    <!-- Versioned tag name -->
                    <argument>${docker.image.name}:${project.version}</argument>
                    <!-- Latest tag name -->
                    <argument>${docker.image.name}:latest</argument>
                  </arguments>
                </configuration>
              </execution>
              <execution>
                <id>stop-buildkit</id>
                <goals>
                  <goal>exec</goal>
                </goals>
                <phase>install</phase>
                <configuration>
                  <executable>sh</executable>
                  <arguments>
                    <argument>stop-buildkit.sh</argument>
                    <argument>${docker-builder.image.name}</argument>
                  </arguments>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>push-docker-image</id>
      <activation>
        <activeByDefault>false</activeByDefault>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <configuration>
              <includeProjectDependencies>true</includeProjectDependencies>
              <includePluginDependencies>false</includePluginDependencies>
            </configuration>
            <dependencies>
              <dependency>
                <groupId>com.adobe.testing</groupId>
                <artifactId>s3mock</artifactId>
                <version>${project.version}</version>
                <classifier>exec</classifier>
                <type>jar</type>
              </dependency>
            </dependencies>
            <executions>
              <!-- Declare start/stop here again as we can't be sure if the regular stop goal was
               executed before the "push-docker-image" goal. -->
              <execution>
                <id>release-start-buildkit</id>
                <goals>
                  <goal>exec</goal>
                </goals>
                <phase>prepare-package</phase>
                <configuration>
                  <executable>sh</executable>
                  <arguments>
                    <argument>start-buildkit.sh</argument>
                    <argument>${docker-builder.image.name}</argument>
                  </arguments>
                </configuration>
              </execution>
              <execution>
                <id>build-and-push-docker-image</id>
                <goals>
                  <goal>exec</goal>
                </goals>
                <phase>install</phase>
                <configuration>
                  <executable>sh</executable>
                  <arguments>
                    <argument>push-docker-image.sh</argument>
                    <argument>${docker-builder.image.name}</argument>
                    <!-- Versioned tag name -->
                    <argument>${docker.image.name}:${project.version}</argument>
                    <!-- Latest tag name -->
                    <argument>${docker.image.name}:latest</argument>
                  </arguments>
                </configuration>
              </execution>
              <execution>
                <id>release-stop-buildkit</id>
                <goals>
                  <goal>exec</goal>
                </goals>
                <phase>install</phase>
                <configuration>
                  <executable>sh</executable>
                  <arguments>
                    <argument>stop-buildkit.sh</argument>
                    <argument>${docker-builder.image.name}</argument>
                  </arguments>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
