apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: {{ template "dragon-web.fullname" . }}
  labels:
    app: {{ template "dragon-web.name" . }}
    chart: {{ template "dragon-web.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  replicas: {{ .Values.frontend.replicaCount }}
  rollingUpdate:
    maxSurge: 25%
    maxUnavailable: 50%
  selector:
    matchLabels:
      app: {{ template "dragon-web.name" . }}
      release: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app: {{ template "dragon-web.name" . }}
        release: {{ .Release.Name }}
    spec:
      serviceAccountName: {{ required "Service account is required" .Values.serviceAccountName }}
      containers:
        - name: sitemap
          env:
            - name: DRAKEMALL_API_ADDR
              value: https://api.drakemall.com
            - name: SITEMAP_HOSTNAME
              value: https://{{ required "Domain name is required" .Values.domainName }}
          image: "{{ .Values.sitemap.image.repository }}:{{ .Values.sitemap.image.tag }}"
          imagePullPolicy: IfNotPresent
          livenessProbe:
            exec:
              command:
              - curl
              - -f
              - http://localhost:8090/health
            initialDelaySeconds: 10
            failureThreshold: 2
            periodSeconds: 10
            timeoutSeconds: 10
          resources:
            limits:
              memory: "128Mi"
            requests:
              memory: "64Mi"
        - name: {{ .Chart.Name }}
          image: "{{ .Values.frontend.image.repository }}:{{ .Values.frontend.image.tag }}"
          imagePullPolicy: {{ .Values.frontend.image.pullPolicy }}
          env:
{{ toYaml .Values.frontend.image.env | indent 12 }}
            - name: SERVICE_PORT
              value: "5000"
            - name: GRAPHQL_SERVER_URL
              value: "{{ .Values.graphqlUrl }}"
            - name: AUTH_URL
              value: https://old.drakemall.com/auth/{0}
            - name: AUTH_CALLBACK_URL
              value: "https://{{ .Values.domainName }}/"
            - name: WEB_SERVICE_URL
              value: "{{ .Values.domainName }}"
            - name: PRERENDER_ENABLED
              value: "yes"
            - name: PRERENDER_SERVICE_URL
              value: http://service.prerender.io
            - name: PRERENDER_TOKEN
              value: S6gWo8R1lIaYzYqPLvWW
            - name: SERVE_S3_ASSETS_ENABLED
              value: "yes"
            - name: S3_BUCKET_ASSETS_FOLDER
              value: "https://drakemall-assets.s3.eu-central-1.amazonaws.com/dragon"
          ports:
            - name: web-http
              containerPort: 5000
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /
              port: web-http
          readinessProbe:
            httpGet:
              path: /
              port: web-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 }}
        - name: {{ .Chart.Name }}-nginx
          image: "{{ .Values.nginx_proxy.image.repository }}:{{ .Values.nginx_proxy.image.tag }}"
          imagePullPolicy: {{ .Values.nginx_proxy.image.pullPolicy }}
          env:
            - name: APP_ENV
              value: production
            - name: DOMAIN_NAME
              value: {{ required "A valid domainName is required" .Values.domainName }}
            - name: DRAKEMALL_URL
              value: "https://drakemall.com"
            - name: WEB_SERVICE_URL
              value: drakemall.com
            - name: API_GATEWAY_SERVER
              value: localhost:5000
            - name: SITEMAP_SERVER
              value: localhost:8090
            - name: COUNTY_BLACKLIST
              value: "SK|MT"
            - name: PRERENDER_HOST
              value: service.prerender.io
            - name: PRERENDER_TOKEN
              value: S6gWo8R1lIaYzYqPLvWW
            - name: PORT
              value: "80"
          ports:
            - name: http
              containerPort: 80
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /assets/healthy.html
              port: http
            failureThreshold: 3
            initialDelaySeconds: 5
            timeoutSeconds: 10
          readinessProbe:
            httpGet:
              path: /assets/healthy.html
              port: http
            failureThreshold: 3
            initialDelaySeconds: 5
            timeoutSeconds: 10
