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

    Copyright 2015-2017 Hewlett Packard Enterprise Development LP.

    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.github.cafdataprocessing</groupId>
        <artifactId>processing-utilities-aggregator</artifactId>
        <version>1.2.0-49</version>
    </parent>

    <artifactId>data-processing-databases-container</artifactId>
    <packaging>pom</packaging>

    <properties>
        <caf.container.databases.name>${dockerDataProcessingOrg}data-processing-databases${dockerProjectVersion}</caf.container.databases.name>
        <caf.container.javapostgres.name>cafapi/java-postgres:1.11.0-218</caf.container.javapostgres.name>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.github.cafdataprocessing</groupId>
            <artifactId>boilerplate-db</artifactId>
            <classifier>jar-with-dependencies</classifier>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>com.github.cafdataprocessing</groupId>
            <artifactId>corepolicy-database</artifactId>
        </dependency>
        <!-- pull in open source handlers -->
        <dependency>
            <groupId>com.github.cafdataprocessing</groupId>
            <artifactId>worker-policy-binary-hash-worker-handler</artifactId>
            <version>${caf.worker.policy.version}</version>
        </dependency>
        <dependency>
            <groupId>com.github.cafdataprocessing</groupId>
            <artifactId>worker-policy-boilerplate-worker-handler</artifactId>
            <version>${caf.worker.policy.version}</version>
        </dependency>
        <dependency>
            <groupId>com.github.cafdataprocessing</groupId>
            <artifactId>worker-policy-elasticsearch-classification-worker-handler</artifactId>
            <version>${caf.worker.policy.version}</version>
        </dependency>
        <dependency>
            <groupId>com.github.cafdataprocessing</groupId>
            <artifactId>worker-policy-document-worker-handler</artifactId>
            <version>${caf.worker.policy.version}</version>
        </dependency>
        <dependency>
            <groupId>com.github.cafdataprocessing</groupId>
            <artifactId>worker-policy-field-mapping-handler</artifactId>
            <version>${caf.worker.policy.version}</version>
        </dependency>
        <dependency>
            <groupId>com.github.cafdataprocessing</groupId>
            <artifactId>worker-policy-generic-queue-handler</artifactId>
            <version>${caf.worker.policy.version}</version>
        </dependency>
        <dependency>
            <groupId>com.github.cafdataprocessing</groupId>
            <artifactId>worker-policy-markup-worker-handler</artifactId>
            <version>${caf.worker.policy.version}</version>
        </dependency>
        <dependency>
            <groupId>com.github.cafdataprocessing</groupId>
            <artifactId>worker-policy-stop-handler</artifactId>
            <version>${caf.worker.policy.version}</version>
        </dependency>
        <dependency>
            <groupId>com.github.cafdataprocessing</groupId>
            <artifactId>worker-policy-type-registrant</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>io.fabric8</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>${fabric8.docker.maven.version}</version>
                <executions>
                    <execution>
                        <id>docker-build</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>build</goal>
                        </goals>
                        <configuration>
                            <skip>false</skip>
                        </configuration>
                    </execution>
                    <execution>
                        <id>docker-start</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>docker-stop</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>docker-push</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>push</goal>
                        </goals>
                        <configuration>
                            <filter>data-processing-databases</filter>
                        </configuration>
                    </execution>
                </executions>
                <configuration>
                    <autoPull>always</autoPull>
                    <images>
                        <image>
                            <alias>data-processing-databases</alias>
                            <name>${caf.container.databases.name}</name>
                            <build>
                                <from>${caf.container.javapostgres.name}</from>
                                <labels>
                                    <Build.Number>${project.version}</Build.Number>
                                    <Build.Date>${maven.build.timestamp}</Build.Date>
                                    <Git.Branch>${git.branch}</Git.Branch>
                                    <Git.Commit>${git.revision}</Git.Commit>
                                </labels>
                                <optimise>true</optimise>
                                <assembly>
                                    <mode>tar</mode>
                                    <basedir>/</basedir>
                                    <inline>
                                        <dependencySets>
                                            <dependencySet>
                                                <fileMode>0755</fileMode>
                                                <useProjectArtifact>true</useProjectArtifact>
                                                <includes>
                                                    <include>com.github.cafdataprocessing:boilerplate-db</include>
                                                </includes>
                                                <outputFileNameMapping>boilerplate-db.jar</outputFileNameMapping>
                                            </dependencySet>
                                            <dependencySet>
                                                <fileMode>0755</fileMode>
                                                <useProjectArtifact>true</useProjectArtifact>
                                                <includes>
                                                    <include>com.github.cafdataprocessing:corepolicy-database</include>
                                                </includes>
                                                <outputFileNameMapping>corepolicy-database.jar</outputFileNameMapping>
                                            </dependencySet>
                                            <dependencySet>
                                                <useProjectArtifact>false</useProjectArtifact>
                                                <useTransitiveDependencies>false</useTransitiveDependencies>
                                                <includes>
                                                    <include>
                                                        com.github.cafdataprocessing:worker-policy-type-registrant
                                                    </include>
                                                </includes>
                                                <outputDirectory>/registrant</outputDirectory>
                                            </dependencySet>
                                            <!-- pull in all other dependencies (handlers) except the database installers and register app -->
                                            <dependencySet>
                                                <fileMode>0755</fileMode>
                                                <useProjectArtifact>true</useProjectArtifact>
                                                <excludes>
                                                    <exclude>com.github.cafdataprocessing:corepolicy-database</exclude>
                                                    <exclude>com.github.cafdataprocessing:boilerplate-db</exclude>
                                                    <exclude>com.github.cafdataprocessing:worker-policy-type-registrant</exclude>
                                                </excludes>
                                                <outputDirectory>/handlers</outputDirectory>
                                            </dependencySet>
                                        </dependencySets>
                                        <fileSets>
                                            <fileSet>
                                                <directory>/scripts</directory>
                                                <outputDirectory>/docker-entrypoint-initdb.d</outputDirectory>
                                                <lineEnding>unix</lineEnding>
                                                <includes>
                                                    <include>setup.sh</include>
                                                </includes>
                                                <fileMode>0755</fileMode>
                                            </fileSet>
                                            <fileSet>
                                                <directory>/scripts/install</directory>
                                                <outputDirectory>/</outputDirectory>
                                                <lineEnding>unix</lineEnding>
                                                <includes>
                                                    <include>*.sh</include>
                                                </includes>
                                                <fileMode>0755</fileMode>
                                            </fileSet>
                                            <fileSet>
                                                <directory>/scripts/base-data</directory>
                                                <outputDirectory>/</outputDirectory>
                                                <lineEnding>unix</lineEnding>
                                                <includes>
                                                    <include>*.sh</include>
                                                </includes>
                                                <fileMode>0755</fileMode>
                                            </fileSet>
                                        </fileSets>
                                    </inline>
                                </assembly>
                            </build>
                            <run>
                                <ports>
                                    <port>${postgres.db.port}:5432</port>
                                </ports>
                                <env>
                                    <CAF_BOILERPLATE_DB_NAME>boilerplate</CAF_BOILERPLATE_DB_NAME>
                                    <CAF_CLASSIFICATION_DB_NAME>classification</CAF_CLASSIFICATION_DB_NAME>
                                    <CAF_WORKFLOW_DB_NAME>workflow</CAF_WORKFLOW_DB_NAME>
                                    <POSTGRES_PASSWORD>root</POSTGRES_PASSWORD>
                                    <POSTGRES_USER>postgres</POSTGRES_USER>
                                </env>
                                <wait>
                                    <log>PostgreSQL init process complete</log>
                                    <time>600000</time>
                                    <shutdown>500</shutdown>
                                </wait>
                                <log>
                                    <enabled>true</enabled>
                                </log>
                            </run>
                        </image>
                    </images>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>use-default-fixed-ports</id>
            <properties>
                <postgres.db.port>5432</postgres.db.port>
            </properties>
        </profile>
        <!-- profile to optionally disable build of a container, you can enable this profile, and run your tests against
        a fixed container without rebuilding each time. -->
        <profile>
            <id>skip-build-docker-container</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <version>${fabric8.docker.maven.version}</version>
                        <executions>
                            <execution>
                                <id>build-docker-container</id>
                                <phase>compile</phase>
                                <goals>
                                    <goal>build</goal>
                                </goals>
                                <configuration>
                                    <skip>true</skip>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>