{{- if .Values.web.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "finaegis.fullname" . }}-web
  labels:
    {{- include "finaegis.labels" . | nindent 4 }}
    app.kubernetes.io/component: web
spec:
  {{- if not .Values.web.autoscaling.enabled }}
  replicas: {{ .Values.web.replicaCount }}
  {{- end }}
  selector:
    matchLabels:
      {{- include "finaegis.selectorLabels" . | nindent 6 }}
      app.kubernetes.io/component: web
  template:
    metadata:
      annotations:
        checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
      labels:
        {{- include "finaegis.selectorLabels" . | nindent 8 }}
        app.kubernetes.io/component: web
    spec:
      {{- with .Values.global.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      securityContext:
        runAsNonRoot: true
        runAsUser: 82
        fsGroup: 82
      containers:
        - name: web
          image: {{ include "finaegis.image" . }}
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: http
              containerPort: 80
              protocol: TCP
          envFrom:
            - configMapRef:
                name: {{ include "finaegis.configMapName" . }}
            {{- if .Values.externalSecrets.enabled }}
            - secretRef:
                name: {{ include "finaegis.secretName" . }}
            {{- end }}
          livenessProbe:
            {{- toYaml .Values.web.livenessProbe | nindent 12 }}
          readinessProbe:
            {{- toYaml .Values.web.readinessProbe | nindent 12 }}
          resources:
            {{- toYaml .Values.web.resources | nindent 12 }}
          volumeMounts:
            - name: storage
              mountPath: /var/www/html/storage/logs
              subPath: logs
            - name: storage
              mountPath: /var/www/html/storage/framework/cache
              subPath: cache
      volumes:
        - name: storage
          emptyDir: {}
      {{- with .Values.web.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.web.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.web.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
{{- end }}
