apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "firefly.fullname" . }}
  namespace: {{ .Values.global.namespace }}
  labels:
    {{- include "firefly.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.firefly.replicaCount }}
  selector:
    matchLabels:
      {{- include "firefly.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      labels:
        {{- include "firefly.selectorLabels" . | nindent 8 }}
    spec:
      containers:
      - name: firefly-core
        image: "{{ .Values.firefly.image.repository }}:{{ .Values.firefly.image.tag }}"
        imagePullPolicy: {{ .Values.firefly.image.pullPolicy }}
        env:
        - name: FF_DATABASE_TYPE
          value: {{ .Values.firefly.config.database.type }}
        - name: FF_DATABASE_URL
          value: postgres://{{ .Values.firefly.config.database.username }}:$(DB_PASSWORD)@{{ .Values.firefly.config.database.host }}:{{ .Values.firefly.config.database.port }}/{{ .Values.firefly.config.database.database }}?sslmode=disable
        - name: DB_PASSWORD
          valueFrom:
            secretKeyRef:
              name: firefly-secrets
              key: db-password
        - name: FF_BLOCKCHAIN_TYPE
          value: {{ .Values.firefly.config.blockchain.type }}
        - name: FF_BLOCKCHAIN_RPC
          value: {{ .Values.firefly.config.blockchain.rpc.http }}
        - name: FF_BLOCKCHAIN_WS
          value: {{ .Values.firefly.config.blockchain.rpc.ws }}
        - name: FF_CHAIN_ID
          value: "{{ .Values.firefly.config.blockchain.chainId }}"
        - name: FF_NODE_NAME
          value: firefly-node-1
        - name: FF_API_PUBLICURL
          value: {{ .Values.firefly.config.api.publicURL }}
        - name: FF_IPFS_API
          value: {{ .Values.firefly.config.ipfs.api }}
        - name: FF_IPFS_GATEWAY
          value: {{ .Values.firefly.config.ipfs.gateway }}
        - name: FF_LOGGING_LEVEL
          value: info
        ports:
        - containerPort: {{ .Values.firefly.config.api.port }}
          name: api
        - containerPort: 5001
          name: metrics
        resources:
          {{- toYaml .Values.firefly.resources | nindent 10 }}
        livenessProbe:
          httpGet:
            path: /api/v1/status
            port: api
          initialDelaySeconds: 60
          periodSeconds: 30
        readinessProbe:
          httpGet:
            path: /api/v1/status
            port: api
          initialDelaySeconds: 30
          periodSeconds: 10
---
apiVersion: v1
kind: Service
metadata:
  name: {{ include "firefly.fullname" . }}-api
  namespace: {{ .Values.global.namespace }}
  labels:
    {{- include "firefly.labels" . | nindent 4 }}
spec:
  type: ClusterIP
  ports:
  - port: {{ .Values.firefly.config.api.port }}
    targetPort: api
    protocol: TCP
    name: api
  - port: 5001
    targetPort: metrics
    protocol: TCP
    name: metrics
  selector:
    {{- include "firefly.selectorLabels" . | nindent 4 }}

