<?xml version="1.0" encoding="UTF-8"?>
<!-- SPDX-License-Identifier: Apache-2.0 -->
<!-- Copyright Contributors to the ODPi Egeria project. -->

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

    <parent>
        <artifactId>open-metadata-docker</artifactId>
        <groupId>org.odpi.egeria</groupId>
        <version>2.3-SNAPSHOT</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>

    <scm>
        <connection>scm:git:git://github.com/odpi/egeria.git</connection>
        <developerConnection>scm:git:ssh://github.com/odpi/egeria.git</developerConnection>
        <url>http://github.com/odpi/egeria/tree/master</url>
    </scm>

    <name>Docker image - Egeria</name>
    <description>
        Samples, Helm charts to deploy Egeria and associated components such as docker image build scripts
    </description>

    <artifactId>open-metadata-docker-egeria</artifactId>

    <packaging>pom</packaging>

    <!-- Use assemblies as built for distribution -->
    <dependencies>
        <dependency>
            <groupId>org.odpi.egeria</groupId>
            <artifactId>open-metadata-assemblies</artifactId>
            <classifier>distribution</classifier>
            <type>pom</type>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>pl.project13.maven</groupId>
                <artifactId>git-commit-id-plugin</artifactId>
                <executions>
                    <execution>
                        <id>get git version info</id>
                        <goals>
                            <goal>revision</goal>
                        </goals>
                        <phase>initialize</phase>
                    </execution>
                </executions>
                <configuration>
                    <dotGitDirectory>${maven.multiModuleProjectDirectory}/.git</dotGitDirectory>
                    <prefix>git</prefix>
                    <dateFormatTimeZone>UTC</dateFormatTimeZone>
                    <skipPoms>false</skipPoms>
                </configuration>
            </plugin>

            <!-- We need to copy required assemblies locally - Docker requires this due to the way all files
                 in context are sent to the server -->
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-assemblies-for-docker</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/assembly</outputDirectory>
                            <overwrite>true</overwrite>
                            <resources>
                                <resource>
                                    <directory>../../../../open-metadata-distribution/open-metadata-assemblies/target/egeria-${project.version}-distribution/egeria-omag-${project.version}</directory>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!-- Setup the docker build.
                 Note - bound to 'install' phase as deploy causes push of maven artifacts
            -->
            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>dockerfile-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>build-and-tag-latest</id>
                        <phase>install</phase>
                        <goals>
                            <goal>build</goal>
                        </goals>
                        <configuration>
                            <tag>${project.version}</tag>
                        </configuration>
                    </execution>
                    <execution>
                        <id>tag-version</id>
                        <phase>install</phase>
                        <goals>
                            <goal>tag</goal>
                        </goals>
                        <configuration>
                            <tag>${project.version}</tag>
                        </configuration>
                    </execution>
                    <execution>
                        <id>push-version</id>
                        <phase>install</phase>
                        <goals>
                            <goal>push</goal>
                        </goals>
                        <configuration>
                            <tag>${project.version}</tag>
                        </configuration>
                    </execution>
                </executions>
                <configuration>
                    <repository>${docker.registry}/${docker.repo}/egeria</repository>
                    <buildArgs>
                        <VCS_REF>${git.commit.id.describe}</VCS_REF>
                        <VCS_DATE>${git.commit.time}</VCS_DATE>
                        <BUILD_TIME>${git.build.time}</BUILD_TIME>
                        <VCS_ORIGIN>${git.remote.origin.url}</VCS_ORIGIN>
                    </buildArgs>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>tag-latest</id>
            <activation>
                <property>
                    <name>docker.taglatest</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.spotify</groupId>
                        <artifactId>dockerfile-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>tag-latest</id>
                                <phase>install</phase>
                                <goals>
                                    <goal>tag</goal>
                                </goals>
                                <configuration>
                                    <tag>latest</tag>
                                </configuration>
                            </execution>
                            <execution>
                                <id>push-latest</id>
                                <phase>install</phase>
                                <goals>
                                    <goal>push</goal>
                                </goals>
                                <configuration>
                                    <tag>latest</tag>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

</project>
