apiVersion: apps/v1
kind: Deployment
metadata:
  name: invoice
  namespace: jhipster
spec:
  replicas: 1
  selector:
    matchLabels:
      app: invoice
      version: "v1"
  template:
    metadata:
      labels:
        app: invoice
        version: "v1"
    spec:
      initContainers:
        - name: init-ds
          image: busybox:latest
          command:
            - '/bin/sh'
            - '-c'
            - |
                while true
                do
                  rt=$(nc -z -w 1 invoice-mysql 3306)
                  if [ $? -eq 0 ]; then
                    echo "DB is UP"
                    break
                  fi
                  echo "DB is not yet reachable;sleep for 10s before retry"
                  sleep 10
                done
      containers:
      - name: invoice-app
        image: deepu105/invoice
        env:
        - name: SPRING_PROFILES_ACTIVE
          value: prod
        - name: JHIPSTER_SECURITY_AUTHENTICATION_JWT_BASE64_SECRET
          valueFrom:
            secretKeyRef:
              name: jwt-secret
              key: secret
        - name: SPRING_DATASOURCE_URL
          value: jdbc:mysql://invoice-mysql.jhipster.svc.cluster.local:3306/invoice?useUnicode=true&characterEncoding=utf8&useSSL=false
        - name: SPRING_SLEUTH_PROPAGATION_KEYS
          value: "x-request-id,x-ot-span-context"
        - name: JAVA_OPTS
          value: " -Xmx256m -Xms256m"
        resources:
          requests:
            memory: "256Mi"
            cpu: "500m"
          limits:
            memory: "512Mi"
            cpu: "1"
        ports:
        - name: http
          containerPort: 8082
        readinessProbe:
          httpGet:
            path: /invoice/management/health
            port: http
          initialDelaySeconds: 20
          periodSeconds: 15
          failureThreshold: 6
        livenessProbe:
          httpGet:
            path: /invoice/management/health
            port: http
          initialDelaySeconds: 120
