<?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/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.atlassian.jira.plugins</groupId>
        <artifactId>jira-greenhopper-parent-pom</artifactId>
        <version>9.13.0-int-2094</version>
    </parent>

    <artifactId>greenhopper-dbprovide</artifactId>
    <packaging>pom</packaging>

    <name>Jira Agile Database provide</name>
    <description>Database provide configuration for Jira Agile</description>

    <properties>
        <datasource.hostname>localhost</datasource.hostname>
        <datasource.username>jirauser2</datasource.username>
        <datasource.password>jirauser2</datasource.password>

        <db.type>postgres</db.type>
        <db.dump />
        <db.dumpLogsOnError>ALL</db.dumpLogsOnError>
        <jiradb.settingsFile>${project.build.directory}/boxdb.properties</jiradb.settingsFile>
        <jiradb.performChildModuleCheck>false</jiradb.performChildModuleCheck>
    </properties>

    <profiles>
        <profile>
            <id>dbprovide</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.atlassian.maven.plugins</groupId>
                        <artifactId>jiradb-maven-plugin</artifactId>
                        <version>${jiradb.version}</version>
                        <executions>
                            <execution>
                                <id>prepare-db</id>
                                <phase>generate-test-resources</phase>
                                <goals>
                                    <goal>start</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>dbstop</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.atlassian.maven.plugins</groupId>
                        <artifactId>jiradb-maven-plugin</artifactId>
                        <version>${jiradb.version}</version>
                        <executions>
                            <execution>
                                <id>clean-db</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>stop</goal>
                                    <goal>clean</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>pgpool</id>
            <properties>
                <pgpool.version>4.4.3</pgpool.version>
                <postgres.node.version>15.3.0</postgres.node.version>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <configuration>
                            <autoCreateCustomNetworks>true</autoCreateCustomNetworks>
                            <images>
                                <image>
                                    <alias>pg-0</alias>
                                    <name>bitnami/postgresql-repmgr:${postgres.node.version}</name>
                                    <run>
                                        <containerNamePattern>%a</containerNamePattern>
                                        <env>
                                            <REPMGR_PARTNER_NODES>pg-0,pg-1</REPMGR_PARTNER_NODES>
                                            <REPMGR_PRIMARY_HOST>pg-0</REPMGR_PRIMARY_HOST>
                                            <REPMGR_NODE_NAME>pg-0</REPMGR_NODE_NAME>
                                            <REPMGR_NODE_NETWORK_NAME>pg-0</REPMGR_NODE_NETWORK_NAME>
                                            <REPMGR_PASSWORD>repmgr_pass</REPMGR_PASSWORD>
                                            <POSTGRESQL_POSTGRES_PASSWORD>postgresbox</POSTGRESQL_POSTGRES_PASSWORD>
                                            <POSTGRESQL_USERNAME>customuser</POSTGRESQL_USERNAME>
                                            <POSTGRESQL_PASSWORD>pg_pass</POSTGRESQL_PASSWORD>
                                            <POSTGRESQL_DATABASE>jiradb</POSTGRESQL_DATABASE>
                                        </env>
                                        <network>
                                            <mode>custom</mode>
                                            <name>pgpool-network</name>
                                        </network>
                                        <log>
                                            <prefix>database</prefix>
                                            <date>default</date>
                                            <color>cyan</color>
                                        </log>
                                        <wait>
                                            <log>monitoring cluster primary "pg-0"</log>
                                            <time>1200000</time>
                                        </wait>
                                    </run>
                                </image>
                                <image>
                                    <alias>pg-1</alias>
                                    <name>bitnami/postgresql-repmgr:${postgres.node.version}</name>
                                    <run>
                                        <containerNamePattern>%a</containerNamePattern>
                                        <env>
                                            <REPMGR_PARTNER_NODES>pg-0,pg-1</REPMGR_PARTNER_NODES>
                                            <REPMGR_PRIMARY_HOST>pg-0</REPMGR_PRIMARY_HOST>
                                            <REPMGR_NODE_NAME>pg-1</REPMGR_NODE_NAME>
                                            <REPMGR_NODE_NETWORK_NAME>pg-1</REPMGR_NODE_NETWORK_NAME>
                                            <REPMGR_PASSWORD>repmgr_pass</REPMGR_PASSWORD>
                                            <POSTGRESQL_POSTGRES_PASSWORD>postgresbox</POSTGRESQL_POSTGRES_PASSWORD>
                                            <POSTGRESQL_USERNAME>customuser</POSTGRESQL_USERNAME>
                                            <POSTGRESQL_PASSWORD>pg_pass</POSTGRESQL_PASSWORD>
                                            <POSTGRESQL_DATABASE>jiradb</POSTGRESQL_DATABASE>
                                        </env>
                                        <network>
                                            <mode>custom</mode>
                                            <name>pgpool-network</name>
                                        </network>
                                        <log>
                                            <prefix>database</prefix>
                                            <date>default</date>
                                            <color>cyan</color>
                                        </log>
                                        <dependsOn>
                                            <container>pg-0</container>
                                        </dependsOn>
                                        <wait>
                                            <log>Waiting for primary node...</log>
                                            <time>1200000</time>
                                        </wait>
                                    </run>
                                </image>
                                <image>
                                    <alias>pgpool</alias>
                                    <name>bitnami/pgpool:${pgpool.version}</name>
                                    <run>
                                        <containerNamePattern>%a</containerNamePattern>
                                        <ports>
                                            <port>5433:5432</port>
                                        </ports>
                                        <env>
                                            <PGPOOL_BACKEND_NODES>0:pg-0:5432,1:pg-1:5432</PGPOOL_BACKEND_NODES>
                                            <PGPOOL_SR_CHECK_USER>customuser</PGPOOL_SR_CHECK_USER>
                                            <PGPOOL_SR_CHECK_PASSWORD>pg_pass</PGPOOL_SR_CHECK_PASSWORD>
                                            <PGPOOL_ENABLE_LDAP>no</PGPOOL_ENABLE_LDAP>
                                            <PGPOOL_ADMIN_USERNAME>admin</PGPOOL_ADMIN_USERNAME>
                                            <PGPOOL_ADMIN_PASSWORD>jira</PGPOOL_ADMIN_PASSWORD>
                                            <PGPOOL_POSTGRES_USERNAME>postgres</PGPOOL_POSTGRES_USERNAME>
                                            <PGPOOL_POSTGRES_PASSWORD>postgresbox</PGPOOL_POSTGRES_PASSWORD>
                                            <PGPOOL_HEALTH_CHECK_PERIOD>5</PGPOOL_HEALTH_CHECK_PERIOD>
                                            <PGPOOL_HEALTH_CHECK_MAX_RETRIES>2</PGPOOL_HEALTH_CHECK_MAX_RETRIES>
                                            <PGPOOL_MAX_POOL>100</PGPOOL_MAX_POOL>
                                            <PGPOOL_DISABLE_LOAD_BALANCE_ON_WRITE>always</PGPOOL_DISABLE_LOAD_BALANCE_ON_WRITE>
                                            <PGPOOL_POSTGRES_CUSTOM_USERS>jirauser2,ao_user</PGPOOL_POSTGRES_CUSTOM_USERS>
                                            <PGPOOL_POSTGRES_CUSTOM_PASSWORDS>jirauser2,ao_password</PGPOOL_POSTGRES_CUSTOM_PASSWORDS>
                                        </env>
                                        <network>
                                            <mode>custom</mode>
                                            <name>pgpool-network</name>
                                        </network>
                                        <log>
                                            <prefix>database</prefix>
                                            <date>default</date>
                                            <color>cyan</color>
                                        </log>
                                        <dependsOn>
                                            <container>pg-1</container>
                                        </dependsOn>
                                        <wait>
                                            <log>pgpool-II successfully started</log>
                                            <time>1200000</time>
                                        </wait>
                                    </run>
                                </image>
                            </images>
                        </configuration>
                        <executions>
                            <execution>
                                <id>start</id>
                                <phase>generate-test-resources</phase>
                                <goals>
                                    <goal>start</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>jira-postgres</id>
            <activation>
                <property>
                    <name>tpm.postgres</name>
                </property>
            </activation>
            <properties>
                <db.type>postgres</db.type>
                <db.version>${tpm.postgres}</db.version>
            </properties>
        </profile>

        <profile>
            <id>jira-mysql</id>
            <activation>
                <property>
                    <name>tpm.mysql</name>
                </property>
            </activation>
            <properties>
                <db.type>mysql</db.type>
                <db.version>${tpm.mysql}</db.version>
            </properties>
        </profile>
    </profiles>

</project>
