<%#
 Copyright 2013-2017 the original author or authors from the JBooter project.

 This file is part of the JBooter project, see https://jbooter.github.io/
 for more information.

 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.
-%>
version: '2'
services:
<%_ if (enableRancherLoadBalancing && hasFrontApp) { _%>
    lb:
      image: rancher/load-balancer-service
      ports:
        # Listen on public port 80 and direct traffic to private port 8080 of the service
        - 80:<%= frontAppPort %>
      links:
        # Target services in the same stack will be listed as a link
        - <%= frontAppName %>:<%= frontAppName %>
<%_ } _%>
<%_ for(var i = 0; i < appConfigs.length; i++) { _%>
<%- appsYaml[i] %>
<%_ } _%>
<%_ if (useKafka) { _%>
    zookeeper:
        image: <%= DOCKER_ZOOKEEPER %>
    kafka:
        image: <%= DOCKER_KAFKA %>
        environment:
            KAFKA_ADVERTISED_HOST_NAME: kafka
            KAFKA_ADVERTISED_PORT: 9092
            KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
            KAFKA_CREATE_TOPICS: "topic-jbooter:1:1"
        #ports:
        #    - 9092:9092  # Uncomment to make Kafka available externally
<%_ } _%>
<%_ if (serviceDiscoveryType == 'eureka') { _%>
    jbooter-registry:
        image: <%= DOCKER_JBOOTER_REGISTRY %>
        #volumes:
        #    - ./central-server-config:/central-config
        # By default the JBooter Registry runs with the "prod" and "native"
        # Spring profiles.
        # "native" profile means the filesystem is used to store data, see
        # http://cloud.spring.io/spring-cloud-config/spring-cloud-config.html
        environment:
            - SPRING_PROFILES_ACTIVE=dev,native
            - SECURITY_USER_PASSWORD=<%= adminPassword %>
            <%_ if (monitoring === 'elk') { _%>
            - JBOOTER_LOGGING_LOGSTASH_ENABLED=true
            - JBOOTER_LOGGING_LOGSTASH_HOST=jbooter-logstash
            - JBOOTER_METRICS_LOGS_ENABLED=true
            - JBOOTER_METRICS_LOGS_REPORTFREQUENCY=60
            <%_ } _%>
            <%_ if (monitoring === 'prometheus') { _%>
            - JBOOTER_METRICS_PROMETHEUS_ENABLED=true
            - JBOOTER_METRICS_PROMETHEUS_ENDPOINT=/prometheusMetrics
            <%_ } _%>
            - SPRING_CLOUD_CONFIG_SERVER_NATIVE_SEARCH_LOCATIONS=file:./config/
            # Uncomment to use a git configuration source instead of the local filesystem
            # mounted from the registry-config-sidekick volume
            # - GIT_URI=https://github.com/jbooter/jbooter-registry/
            # - GIT_SEARCH_PATHS=central-config
        ports:
            - 8761:8761
        volumes:
          - /config
        volumes_from:
          - registry-config-sidekick
        labels:
          io.rancher.sidekicks: registry-config-sidekick
<%_ } _%>
<%_ if (serviceDiscoveryType == 'consul') { _%>
    consul:
        image: <%= DOCKER_CONSUL %>
        ports:
            - 8300:8300
            - 8500:8500
            - 8600:8600
        command: consul agent -dev -ui -client 0.0.0.0
    consul-config-loader:
        image: <%= DOCKER_CONSUL_CONFIG_LOADER %>
        environment:
            - INIT_SLEEP_SECONDS=5
            - CONSUL_URL=consul
            - CONSUL_PORT=8500
        volumes:
          - /config
        volumes_from:
          - registry-config-sidekick
        labels:
          io.rancher.sidekicks: registry-config-sidekick
<%_ } _%>
<%_ if (serviceDiscoveryType === 'eureka' || serviceDiscoveryType === 'consul') { _%>
    registry-config-sidekick:
        # this docker image must be built with:
        # docker build -t <%= dockerRepositoryName %><% if (dockerRepositoryName !== '') { %>/<% } %>registry-config-sidekick registry-config-sidekick
        image: <%= dockerRepositoryName %><% if (dockerRepositoryName !== '') { %>/<% } %>registry-config-sidekick
        tty: true
        stdin_open: true
        command:
          - cat
        volumes:
          - config:/config
<%_ } _%>
<%_ if (monitoring === 'elk') { _%>
    jbooter-elasticsearch:
        image: <%= DOCKER_JBOOTER_ELASTICSEARCH %>
        ports:
            - 9200:9200
            - 9300:9300
        # Uncomment this section to have elasticsearch data persisted to a volume
        #volumes:
        #   - ./log-data:/usr/share/elasticsearch/data
    jbooter-logstash:
        image: <%= DOCKER_JBOOTER_LOGSTASH %>
        command: logstash -f /conf/logstash.conf
        ports:
            - 5000:5000/udp
        # Uncomment this section to have logstash config loaded from a volume
        #volumes:
        #    - ./log-conf/:/conf
    jbooter-console:
        image: <%= DOCKER_JBOOTER_CONSOLE %>
        ports:
            - 5601:5601
<%_ } _%>
