<%#
 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.
-%>
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: <%= app.baseName.toLowerCase() %>
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: <%= app.baseName.toLowerCase() %>
    spec:
      containers:
      - name: <%= app.baseName.toLowerCase() %>-app
        image: <%= app.targetImageName %>
        imagePullPolicy: IfNotPresent
        env:
        - name: SPRING_PROFILES_ACTIVE
          value: prod
        <%_ if (app.serviceDiscoveryType === 'eureka') { _%>
        - name: SPRING_CLOUD_CONFIG_URI
          value: http://admin:${jbooter.registry.password}@jbooter-registry.<%= kubernetesNamespace %>.svc.cluster.local:8761/config
        - name: JBOOTER_REGISTRY_PASSWORD
          valueFrom:
            secretKeyRef:
              name: registry-secret
              key: registry-admin-password
        <%_ } _%>
        <%_ if (app.serviceDiscoveryType === 'consul') { _%>
        - name: SPRING_CLOUD_CONSUL_HOST
          value: consul.<%= kubernetesNamespace %>.svc.cluster.local
        - name: SPRING_CLOUD_CONSUL_PORT
          value: "8500"
        <%_ } _%>
        <%_ if (app.prodDatabaseType === 'mysql') { _%>
        - name: SPRING_DATASOURCE_URL
          value: jdbc:mysql://<%= app.baseName.toLowerCase() %>-mysql.<%= kubernetesNamespace %>.svc.cluster.local:3306/<%= app.baseName.toLowerCase() %>?useUnicode=true&characterEncoding=utf8&useSSL=false
        <%_ } _%>
        <%_ if (app.prodDatabaseType === 'mariadb') { _%>
        - name: SPRING_DATASOURCE_URL
          value: jdbc:mariadb://<%= app.baseName.toLowerCase() %>-mariadb.<%= kubernetesNamespace %>.svc.cluster.local:3306/<%= app.baseName.toLowerCase() %>
        <%_ } _%>
        <%_ if (app.prodDatabaseType === 'postgresql') { _%>
        - name: SPRING_DATASOURCE_URL
          value: jdbc:postgresql://<%= app.baseName.toLowerCase() %>-postgresql.<%= kubernetesNamespace %>.svc.cluster.local:5432/<%= app.baseName %>
        <%_ } _%>
        <%_ if (app.prodDatabaseType === 'mongodb') { _%>
        - name: SPRING_DATA_MONGODB_URI
          value: mongodb://<%= app.baseName.toLowerCase() %>-mongodb.<%= kubernetesNamespace %>.svc.cluster.local:27017
        - name: SPRING_DATA_MONGODB_DATABASE
          value: <%= app.baseName %>
        <%_ } _%>
        <%_ if (app.searchEngine === 'elasticsearch') { _%>
        - name: SPRING_DATA_ELASTICSEARCH_CLUSTER_NODES
          value: <%= app.baseName.toLowerCase() %>-elasticsearch.<%= kubernetesNamespace %>.svc.cluster.local:9300
        <%_ } _%>
        <%_ if (app.messageBroker === 'kafka') { _%>
        - name: SPRING_CLOUD_STREAM_KAFKA_BINDER_BROKERS
          value: <%= app.baseName.toLowerCase() %>-kafka.<%= kubernetesNamespace %>.svc.cluster.local
        - name: SPRING_CLOUD_STREAM_KAFKA_BINDER_ZK_NODES
          value: <%= app.baseName.toLowerCase() %>-zookeeper.<%= kubernetesNamespace %>.svc.cluster.local
        <%_ } _%>
        ports:
        - containerPort: <%= app.serverPort %>
