# Copyright 2016 Google Inc. All Rights Reserved.
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you 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() %>
        image: <%= app.targetImageName %>
        env:
        - name: SPRING_PROFILES_ACTIVE
          value: prod
        <%_ if (app.applicationType === 'microservice' || app.applicationType === 'gateway') { _%>
        - name: EUREKA_CLIENT_SERVICEURL_DEFAULTZONE
          value: http://admin:<%= adminPassword %>@jhipster-registry.<%= kubernetesNamespace %>.svc.cluster.local:8761/eureka/
        - name: SPRING_CLOUD_CONFIG_URI
          value: http://admin:<%= adminPassword %>@jhipster-registry.<%= kubernetesNamespace %>.svc.cluster.local:8761/config
        <%_ } _%>
        <%_ 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
        <%_ } _%>
        ports:
        - containerPort: <%= app.serverPort %>
