apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: {{ template "dragon-graphql-i18n.fullname" . }}
  labels:
    app: {{ template "dragon-graphql-i18n.name" . }}
    chart: {{ template "dragon-graphql-i18n.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ template "dragon-graphql-i18n.name" . }}
      release: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app: {{ template "dragon-graphql-i18n.name" . }}
        release: {{ .Release.Name }}
    spec:
      serviceAccountName: {{ required "Service account is required" .Values.serviceAccountName }}
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          env:
{{ toYaml .Values.image.env | indent 12 }}
            {{ if .Values.postgres.enabled }}
            - name: POSTGRES_URI
              value: "{{ .Values.postgres.url }}"
            {{ end }}
            {{ if .Values.redis.enabled }}
            - name: REDIS_URL
              value: "{{ .Values.redis.url }}"
            {{ end }}
          ports:
            - name: http
              containerPort: 5000
              protocol: TCP
          # livenessProbe:
          #   httpGet:
          #     path: /graphql/health
          #     port: http
          # readinessProbe:
          #   httpGet:
          #     path: /graphql/health
          #     port: http
          resources:
{{ toYaml .Values.resources | indent 12 }}
    {{- with .Values.nodeSelector }}
      nodeSelector:
{{ toYaml . | indent 8 }}
    {{- end }}
    {{- with .Values.affinity }}
      affinity:
{{ toYaml . | indent 8 }}
    {{- end }}
    {{- with .Values.tolerations }}
      tolerations:
{{ toYaml . | indent 8 }}
    {{- end }}
