version: '2'
services:
    <%= baseName.toLowerCase() %>-app:
        image: <%= baseName.toLowerCase() %>
        <%_ if (prodDatabaseType == 'mysql' || prodDatabaseType == 'postgresql' || prodDatabaseType == 'mongodb' || applicationType == 'gateway' || prodDatabaseType == 'cassandra' || searchEngine == 'elasticsearch' || applicationType == 'microservice' || applicationType == 'gateway') { _%>
        external_links:
        <%_ } _%>
        <%_ if (prodDatabaseType == 'mysql') { _%>
            - <%= baseName.toLowerCase() %>-mysql:mysql
        <%_ } _%>
        <%_ if (prodDatabaseType == 'mariadb') { _%>
            - <%= baseName.toLowerCase() %>-mariadb:mariadb
        <%_ } _%>
        <%_ if (prodDatabaseType == 'postgresql') { _%>
            - <%= baseName.toLowerCase() %>-postgresql:postgresql
        <%_ } _%>
        <%_ if (prodDatabaseType == 'mongodb') { _%>
            - <%= baseName.toLowerCase() %>-mongodb:mongodb
        <%_ } _%>
        <%_ if (prodDatabaseType == 'cassandra') { _%>
            - <%= baseName.toLowerCase() %>-cassandra:cassandra
        <%_ } _%>
        <%_ if (applicationType == 'gateway' && prodDatabaseType != 'cassandra') { _%>
            # Uncomment to have Cassandra working with the gateway
            # - <%= baseName.toLowerCase() %>-cassandra:cassandra
        <%_ } _%>
        <%_ if (searchEngine == 'elasticsearch') { _%>
            - <%= baseName.toLowerCase() %>-elasticsearch:elasticsearch
        <%_ } _%>
        <%_ if (applicationType == 'microservice' || applicationType == 'gateway' || applicationType == 'uaa') { _%>
            - jh-genesis-registry:registry
        <%_ } _%>
        environment:
            - SPRING_PROFILES_ACTIVE=prod
            <%_ if (applicationType == 'microservice' || applicationType == 'gateway' || applicationType == 'uaa') { _%>
            - SPRING_CLOUD_CONFIG_URI=http://admin:admin@registry:8761/config
            <%_ } _%>
            <%_ if (prodDatabaseType == 'mysql') { _%>
            - SPRING_DATASOURCE_URL=jdbc:mysql://mysql:3306/<%= baseName.toLowerCase() %>?useUnicode=true&characterEncoding=utf8&useSSL=false
            <%_ } _%>
            <%_ if (prodDatabaseType == 'mariadb') { _%>
            - SPRING_DATASOURCE_URL=jdbc:mariadb://mariadb:3306/<%= baseName.toLowerCase() %>
            <%_ } _%>
            <%_ if (prodDatabaseType == 'postgresql') { _%>
            - SPRING_DATASOURCE_URL=jdbc:postgresql://postgresql:5432/<%= baseName %>
            <%_ } _%>
            <%_ if (prodDatabaseType == 'mongodb') { _%>
            - SPRING_DATA_MONGODB_URI=mongodb://mongodb:27017
            - SPRING_DATA_MONGODB_DATABASE=<%= baseName %>
            <%_ } _%>
            <%_ if (applicationType == 'gateway' || prodDatabaseType == 'cassandra') { _%>
            - SPRING_DATA_CASSANDRA_CONTACTPOINTS=cassandra
            - JHGENESIS_SLEEP=30 # gives time for the cassandra cluster to start and execute the migration scripts
            <%_ } else { _%>
            - JHGENESIS_SLEEP=10 # gives time for the database to boot before the application
            <%_ } _%>
            <%_ if (searchEngine == 'elasticsearch') { _%>
            - SPRING_DATA_ELASTICSEARCH_CLUSTER_NODES=elasticsearch:9300
            <%_ } _%>
        <%_ if (applicationType == 'monolith' || applicationType == 'gateway') { _%>
        ports:
            - <%= serverPort %>:<%= serverPort %>
        <%_ } _%>
    <%_ if (prodDatabaseType == 'mysql') { _%>
    <%= baseName.toLowerCase() %>-mysql:
        extends:
            file: mysql.yml
            service: <%= baseName.toLowerCase() %>-mysql
    <%_ } _%>
    <%_ if (prodDatabaseType == 'mariadb') { _%>
    <%= baseName.toLowerCase() %>-mariadb:
        extends:
            file: mariadb.yml
            service: <%= baseName.toLowerCase() %>-mariadb
    <%_ } _%>
    <%_ if (prodDatabaseType == 'postgresql') { _%>
    <%= baseName.toLowerCase() %>-postgresql:
        extends:
            file: postgresql.yml
            service: <%= baseName.toLowerCase() %>-postgresql
    <%_ } _%>
    <%_ if (prodDatabaseType == 'mongodb') { _%>
    <%= baseName.toLowerCase() %>-mongodb:
        extends:
            file: mongodb.yml
            service: <%= baseName.toLowerCase() %>-mongodb
    <%_ } _%>
    <%_ if (prodDatabaseType == 'cassandra') { _%>
    <%= baseName.toLowerCase() %>-cassandra:
        extends:
            file: cassandra-cluster.yml
            service: <%= baseName.toLowerCase() %>-cassandra
    <%= baseName.toLowerCase() %>-cassandra-node:
        image: <%= DOCKER_CASSANDRA %>
        links:
            - <%= baseName.toLowerCase() %>-cassandra:seed
        environment:
            - CASSANDRA_SEEDS=seed
    <%= baseName.toLowerCase() %>-cassandra-migration:
        extends:
            file: cassandra-migration.yml
            service: <%= baseName.toLowerCase() %>-cassandra-migration
        links:
            - <%= baseName.toLowerCase() %>-cassandra
        environment:
            - CREATE_KEYSPACE_SCRIPT=create-keyspace-prod.cql
    <%_ } _%>
    <%_ if (applicationType == 'gateway' && prodDatabaseType != 'cassandra') { _%>
        # Uncomment to have Cassandra working with the gateway
        # extends:
        #     file: cassandra-cluster.yml
        #     service: <%= baseName.toLowerCase() %>-cassandra
    <%_ } _%>
    <%_ if (searchEngine == 'elasticsearch') { _%>
    <%= baseName.toLowerCase() %>-elasticsearch:
        extends:
            file: elasticsearch.yml
            service: <%= baseName.toLowerCase() %>-elasticsearch
    <%_ } _%>
    <%_ if (applicationType == 'microservice' || applicationType == 'gateway' || applicationType == 'uaa') { _%>
    jh-genesis-registry:
        extends:
            file: jh-genesis-registry.yml
            service: jh-genesis-registry
    <%_ } _%>
