<?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>cn.home1</groupId>
        <artifactId>maven-build</artifactId>
        <version>0.0.5.OSS</version>
    </parent>

    <artifactId>build-docker</artifactId>
    <description>Parent pom for docker projects</description>
    <name>build-docker</name>
    <packaging>pom</packaging>

    <properties>
        <io.fabric8_docker-maven-plugin.version>0.26.0</io.fabric8_docker-maven-plugin.version>
        <com.spotify_docker-maven-plugin.version>1.1.1</com.spotify_docker-maven-plugin.version>
        <com.spotify_dockerfile-maven-plugin.version>1.4.2</com.spotify_dockerfile-maven-plugin.version>

        <dockerfile.build.skip>true</dockerfile.build.skip>
        <dockerfile.useMavenSettingsForAuth>false</dockerfile.useMavenSettingsForAuth>
        <docker.registry>nexus3.local:5000</docker.registry>
    </properties>

    <build>
        <extensions>
            <extension>
                <!-- for the dependency type 'docker-info' to be supported -->
                <groupId>com.spotify</groupId>
                <artifactId>dockerfile-maven-extension</artifactId>
                <version>${com.spotify_dockerfile-maven-plugin.version}</version>
            </extension>
        </extensions>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>com.spotify</groupId>
                    <artifactId>dockerfile-maven-plugin</artifactId>
                    <version>${com.spotify_dockerfile-maven-plugin.version}</version>
                    <configuration>
                        <buildArgs>
                            <JAR_FILE>${project.build.finalName}-exec.jar</JAR_FILE>
                        </buildArgs>
                        <tag>${project.version}</tag>
                        <useMavenSettingsForAuth>${dockerfile.useMavenSettingsForAuth}</useMavenSettingsForAuth>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>com.spotify</groupId>
                    <artifactId>docker-maven-plugin</artifactId>
                    <version>${com.spotify_docker-maven-plugin.version}</version>
                    <configuration>
                        <imageTags>
                            <imageTag>${project.version}</imageTag>
                            <!--<imageTag>latest</imageTag>-->
                        </imageTags>
                        <resources>
                            <resource>
                                <targetPath>/</targetPath>
                                <directory>${project.build.directory}</directory>
                                <include>${project.build.finalName}.jar</include>
                                <include>${project.build.finalName}-exec.jar</include>
                            </resource>
                        </resources>
                        <dockerDirectory>${project.basedir}</dockerDirectory>
                        <noCache>true</noCache>
                    </configuration>
                    <executions>
                        <execution>
                            <id>remove-image</id>
                            <phase>clean</phase>
                            <goals>
                                <goal>removeImage</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>io.fabric8</groupId>
                    <artifactId>docker-maven-plugin</artifactId>
                    <version>${io.fabric8_docker-maven-plugin.version}</version>
                </plugin>
            </plugins>
        </pluginManagement>

        <plugins>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>auto-clean-dockerfile</id>
                        <phase>clean</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <delete failonerror="false">
                                    <fileset dir="${project.basedir}" includes="Dockerfile"/>
                                </delete>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>filtering-dockerfile</id>
                        <phase>process-sources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.basedir}</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>src/main/resources/docker</directory>
                                    <filtering>true</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-deploy-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <!-- @formatter:off -->
        <profile>
            <id>ues-private-docker-registry-no-docker-image-prefix</id>
            <activation>
                <property><name>!docker.image.prefix</name></property>
                <file><exists>${basedir}/src/main/resources/docker/Dockerfile</exists></file>
            </activation>
            <build>
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <groupId>com.spotify</groupId>
                            <artifactId>dockerfile-maven-plugin</artifactId>
                            <configuration>
                                <repository>${docker.registry}/${project.artifactId}</repository>
                            </configuration>
                        </plugin>
                        <plugin>
                            <groupId>com.spotify</groupId>
                            <artifactId>docker-maven-plugin</artifactId>
                            <configuration>
                                <imageName>${docker.registry}/${project.artifactId}</imageName>
                            </configuration>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>
        <profile>
            <id>use-docker-hub-docker-image-prefix-no-docker-registry</id>
            <activation>
                <property><name>docker.image.prefix</name></property>
                <file><exists>${basedir}/src/main/resources/docker/Dockerfile</exists></file>
            </activation>
            <build>
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <groupId>com.spotify</groupId>
                            <artifactId>dockerfile-maven-plugin</artifactId>
                            <configuration>
                                <repository>${docker.image.prefix}/${project.artifactId}</repository>
                            </configuration>
                        </plugin>
                        <plugin>
                            <groupId>com.spotify</groupId>
                            <artifactId>docker-maven-plugin</artifactId>
                            <configuration>
                                <imageName>${docker.image.prefix}/${project.artifactId}</imageName>
                            </configuration>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>

        <profile>
            <id>docker-maven-plugin-lifecycle-binding-when-not-publish-deploy-segregation</id>
            <activation>
                <activeByDefault>false</activeByDefault>
                <property>
                    <name>!mvn_deploy_publish_segregation</name>
                </property>
            </activation>
            <properties>
                <dockerfile.build.skip>false</dockerfile.build.skip>
            </properties>
            <build>
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <groupId>com.spotify</groupId>
                            <artifactId>dockerfile-maven-plugin</artifactId>
                            <executions>
                                <execution>
                                    <id>default</id>
                                    <goals>
                                        <goal>build</goal>
                                        <goal>tag</goal>
                                        <goal>push</goal>
                                    </goals>
                                </execution>
                            </executions>
                        </plugin>
                        <plugin>
                            <groupId>com.spotify</groupId>
                            <artifactId>docker-maven-plugin</artifactId>
                            <executions>
                                <execution>
                                    <id>build-image</id>
                                    <phase>package</phase>
                                    <goals><goal>build</goal></goals>
                                </execution>
                                <execution>
                                    <id>push-image</id>
                                    <phase>deploy</phase>
                                    <goals><goal>push</goal></goals>
                                </execution>
                            </executions>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>
        <!-- @formatter:on -->
    </profiles>
</project>
