apiVersion: apps/v1
kind: Deployment
metadata:
  name: deployment-datatorgetbackend
spec:
  replicas: 1
  selector:
    matchLabels:
      app: datatorgetbackend
  template:
    metadata:
      labels:
        app: datatorgetbackend
    spec:
      volumes:
      - name: volume-mongo
        # hostPath:
        #     path: "/datatorget/mongodata"
        #     type: DirectoryOrCreate
        # persistentVolumeClaim:
        #   claimName: volumeclaim-mongo
      containers:
      - name: bokningsapi
        image: datatorgetpoc/bokningsapi
        resources:
          limits:
            memory: "64Mi"
            cpu: "250m"
        ports:
        - containerPort: 30001
        env:
        - name: MESSAGE_SERVICE_HOST
          value: localhost
        - name: MESSAGE_SERVICE_PORT
          value: "5672"
        - name: MESSAGE_SERVICE_USERNAME
          valueFrom:
            secretKeyRef:
              name: secrets-datatorgetbackend
              key: MESSAGE_SERVICE_USERNAME
        - name: MESSAGE_SERVICE_PASSWORD
          valueFrom:
            secretKeyRef:
              name: secrets-datatorgetbackend
              key: MESSAGE_SERVICE_PASSWORD
        - name: MESSAGE_SERVICE_EXCHANGE
          value: "bokning"
        - name: MESSAGE_SERVICE_ENABLED
          value: "True"

      - name: kundapi
        image: datatorgetpoc/kundapi
        resources:
          limits:
            memory: "64Mi"
            cpu: "250m"
        ports:
        - containerPort: 30002
        env:
        - name: MESSAGE_SERVICE_HOST
          value: localhost
        - name: MESSAGE_SERVICE_PORT
          value: "5672"
        - name: MESSAGE_SERVICE_USERNAME
          valueFrom:
            secretKeyRef:
              name: secrets-datatorgetbackend
              key: MESSAGE_SERVICE_USERNAME
        - name: MESSAGE_SERVICE_PASSWORD
          valueFrom:
            secretKeyRef:
              name: secrets-datatorgetbackend
              key: MESSAGE_SERVICE_PASSWORD
        - name: MESSAGE_SERVICE_EXCHANGE
          value: "kund"
        - name: MESSAGE_SERVICE_ENABLED
          value: "True"
          
      - name: kommunikationsapi
        image: datatorgetpoc/kommunikationsapi
        resources:
          limits:
            memory: "64Mi"
            cpu: "250m"
        ports:
        - containerPort: 30003
        env:
        - name: SMTP_SERVICE_HOST
          value: "smtp.sendgrid.net"
        - name: SMTP_SERVICE_PORT
          value: "587"
        - name: SMTP_SERVICE_USERNAME
          valueFrom:
            secretKeyRef:
              name: secrets-datatorgetbackend
              key: SMTP_USERNAME
        - name: SMTP_SERVICE_PASSWORD
          valueFrom:
            secretKeyRef:
              name: secrets-datatorgetbackend
              key: SMTP_PASSWORD
        - name: SENDGRID_APIKEY
          valueFrom:
            secretKeyRef:
              name: secrets-datatorgetbackend
              key: SENDGRID_APIKEY

      - name: betalningsapi
        image: datatorgetpoc/betalningsapi
        resources:
          limits:
            memory: "64Mi"
            cpu: "250m"
        ports:
        - containerPort: 30004
        env:
        - name: MESSAGE_SERVICE_HOST
          value: localhost
        - name: MESSAGE_SERVICE_PORT
          value: "5672"
        - name: MESSAGE_SERVICE_USERNAME
          valueFrom:
            secretKeyRef:
              name: secrets-datatorgetbackend
              key: MESSAGE_SERVICE_USERNAME
        - name: MESSAGE_SERVICE_PASSWORD
          valueFrom:
            secretKeyRef:
              name: secrets-datatorgetbackend
              key: MESSAGE_SERVICE_PASSWORD
        - name: MESSAGE_SERVICE_EXCHANGE
          value: "betalning"
        - name: MESSAGE_SERVICE_ENABLED
          value: "True"

      - name: kopplingstjanst
        image: datatorgetpoc/kopplingstjanst
        resources:
          limits:
            memory: "64Mi"
            cpu: "100m"
        env:
        - name: MESSAGE_SERVICE_HOST
          value: localhost
        - name: MESSAGE_SERVICE_PORT
          value: "5672"
        - name: MESSAGE_SERVICE_USERNAME
          valueFrom:
            secretKeyRef:
              name: secrets-datatorgetbackend
              key: MESSAGE_SERVICE_USERNAME
        - name: MESSAGE_SERVICE_PASSWORD
          valueFrom:
            secretKeyRef:
              name: secrets-datatorgetbackend
              key: MESSAGE_SERVICE_PASSWORD
        - name: BETALNINGSAPI
          value: "http://localhost:30004/api/v1"
        - name: BOKNINGSAPI
          value: "http://localhost:30001/api/v1"
        # volumeMounts:
        #   - mountPath: "/data/db"
        #     name: volume-mongo

      - name: rabbitmq
        image: rabbitmq:management
        resources:
          limits:
            memory: "512Mi"
            cpu: "250m"
        ports:
          - name: http
            protocol: TCP
            containerPort: 15672
          - name: amqp
            protocol: TCP
            containerPort: 5672
        env:
          - name: MY_POD_NAME
            valueFrom:
              fieldRef:
                apiVersion: v1
                fieldPath: metadata.name
          - name: MY_POD_NAMESPACE
            valueFrom:
              fieldRef:
                fieldPath: metadata.namespace
          - name: RABBITMQ_DEFAULT_USER
            valueFrom:
              secretKeyRef:
                name: secrets-datatorgetbackend
                key: MESSAGE_SERVICE_USERNAME
          - name: RABBITMQ_DEFAULT_PASS
            valueFrom:
              secretKeyRef:
                name: secrets-datatorgetbackend
                key: MESSAGE_SERVICE_PASSWORD
          - name: RABBITMQ_USE_LONGNAME
            value: "true"
          - name: K8S_SERVICE_NAME
            value: rabbitmq

      - name: mongo
        image: mongo
        resources:
          limits:
            memory: "128Mi"
            cpu: "250m"
        ports:
        - containerPort: 27017
        # volumeMounts:
        #   - mountPath: "/data/db"
        #     name: volume-mongo
        env:
        - name: MONGO_INITDB_ROOT_USERNAME
          valueFrom:
            secretKeyRef:
              name: secrets-datatorgetbackend
              key: MONGO_USERNAME
        - name: MONGO_INITDB_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: secrets-datatorgetbackend
              key: MONGO_PASSWORD
        - name: MONGO_INITDB_DATABASE
          value: "datatorget"

      - name: mongo-express
        image: mongo-express
        resources:
          limits:
            memory: "128Mi"
            cpu: "250m"
        ports:
        - containerPort: 8081
        env:
        - name: ME_CONFIG_BASICAUTH_USERNAME    
          valueFrom:
            secretKeyRef:
              name: secrets-datatorgetbackend
              key: MONGO_USERNAME
        - name: ME_CONFIG_BASICAUTH_PASSWORD
          valueFrom:
            secretKeyRef:
              name: secrets-datatorgetbackend
              key: MONGO_PASSWORD
        - name: ME_CONFIG_MONGODB_ADMINUSERNAME
          valueFrom:
            secretKeyRef:
              name: secrets-datatorgetbackend
              key: MONGO_USERNAME
        - name: ME_CONFIG_MONGODB_ADMINPASSWORD
          valueFrom:
            secretKeyRef:
              name: secrets-datatorgetbackend
              key: MONGO_PASSWORD
        - name: ME_CONFIG_MONGODB_SERVER
          value: "localhost"
