<?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>

    <packaging>pom</packaging>

    <parent>
        <artifactId>enricher</artifactId>
        <groupId>io.wizzie.enricher</groupId>
        <version>0.5.2</version>
    </parent>

    <artifactId>docker</artifactId>
    <name>docker</name>
    <description>Docker packaging manager</description>

    <properties>
        <docker.google.registry>gcr.io/wizzie-registry</docker.google.registry>
        <docker.hub.registry>wizzieio</docker.hub.registry>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>1.0.0</version>

                <configuration>
                    <forceTags>true</forceTags>

                    <imageName>${project.parent.artifactId}</imageName>

                    <imageTags>
                        <imageTag>${project.version}</imageTag>
                        <imageTag>latest</imageTag>
                    </imageTags>

                    <dockerDirectory>${project.basedir}/build</dockerDirectory>

                    <resources>
                        <resource>
                            <targetPath>/</targetPath>
                            <directory>${project.basedir}/../distribution/target</directory>
                            <include>${project.parent.artifactId}-dist.tar.gz</include>
                        </resource>
                    </resources>

                </configuration>

                <executions>
                    <execution>
                        <id>build-image</id>
                        <phase>package</phase>
                        <goals>
                            <goal>build</goal>
                        </goals>
                    </execution>

                    <execution>
                        <id>tag-google-image</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>tag</goal>
                        </goals>
                        <configuration>
                            <image>${project.parent.artifactId}:${project.version}</image>
                            <newName>${docker.google.registry}/${project.parent.artifactId}:${project.version}</newName>
                        </configuration>
                    </execution>

                    <execution>
                        <id>tag-google-latest-image</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>tag</goal>
                        </goals>
                        <configuration>
                            <image>${project.parent.artifactId}:latest</image>
                            <newName>${docker.google.registry}/${project.parent.artifactId}:latest</newName>
                        </configuration>
                    </execution>

                    <execution>
                        <id>tag-image</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>tag</goal>
                        </goals>
                        <configuration>
                            <image>${project.parent.artifactId}:${project.version}</image>
                            <newName>${docker.hub.registry}/${project.parent.artifactId}:${project.version}</newName>
                        </configuration>
                    </execution>

                    <execution>
                        <id>tag-latest-image</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>tag</goal>
                        </goals>
                        <configuration>
                            <image>${project.parent.artifactId}:latest</image>
                            <newName>${docker.hub.registry}/${project.parent.artifactId}:latest</newName>
                        </configuration>
                    </execution>

                    <execution>
                        <id>push-image-google</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>push</goal>
                        </goals>
                        <configuration>
                            <imageName>${docker.google.registry}/${project.parent.artifactId}:${project.version}</imageName>
                        </configuration>
                    </execution>

                    <execution>
                        <id>push-latest-image-google</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>push</goal>
                        </goals>
                        <configuration>
                            <imageName>${docker.google.registry}/${project.parent.artifactId}:latest</imageName>
                        </configuration>
                    </execution>

                    <execution>
                        <id>push-image-docker-hub</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>push</goal>
                        </goals>
                        <configuration>
                            <imageName>${docker.hub.registry}/${project.parent.artifactId}:${project.version}</imageName>
                            <serverId>docker-hub</serverId>
                            <registryUrl>https://index.docker.io/v1/</registryUrl>
                        </configuration>
                    </execution>

                    <execution>
                        <id>push-latest-image-docker-hub</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>push</goal>
                        </goals>
                        <configuration>
                            <imageName>${docker.hub.registry}/${project.parent.artifactId}:latest</imageName>
                            <serverId>docker-hub</serverId>
                            <registryUrl>https://index.docker.io/v1/</registryUrl>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
