{{- if .Values.euler_copilot.web.enabled -}}
---
apiVersion: v1
kind: Service
metadata:
  name: web-service
  namespace: {{ .Release.Namespace }}
spec:
  type: {{ default "NodePort" .Values.euler_copilot.web.service.type }}
  selector:
    app: web
  ports:
    - port: 8080
      targetPort: 8080
      nodePort: {{ default 30080 .Values.euler_copilot.web.service.nodePort }}

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-deploy
  namespace: {{ .Release.Namespace }}
  labels:
    app: web
spec:
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      annotations:
        checksum/config: {{ include (print $.Template.BasePath "/web/web-config.yaml") . | sha256sum }}
      labels:
        app: web
    spec:
      automountServiceAccountToken: false
      containers:
        - name: web
          image: {{ .Values.euler_copilot.web.image | default (printf "%s/neocopilot/euler-copilot-web:0.10.0-%s" (.Values.globals.imageRegistry | default "hub.oepkgs.net") (.Values.globals.arch | default "x86")) }}
          imagePullPolicy: {{ default "IfNotPresent" .Values.globals.imagePullPolicy }}
          ports:
            - containerPort: 8080
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /
              port: 8080
              scheme: HTTP
            failureThreshold: 5
            initialDelaySeconds: 60
            periodSeconds: 90
          env:
            - name: TZ
              value: "Asia/Shanghai"
          volumeMounts:
            - mountPath: /config
              name: web-config-volume
            - mountPath: /var/lib/nginx/tmp
              name: web-tmp
            - mountPath: /opt/.env
              name: web-env-volume
              subPath: .env
            - mountPath: /usr/share/nginx/html/static
              name: web-static
          resources:
            requests:
              cpu: 0.05
              memory: 64Mi
            limits:
              {{ toYaml .Values.euler_copilot.web.resourceLimits | nindent 14 }}
          securityContext:
            readOnlyRootFilesystem: {{ default false .Values.euler_copilot.web.readOnly }}
      restartPolicy: Always
      volumes:
        - name: web-static
          persistentVolumeClaim:
            claimName: web-static
        - name: web-config-volume
          emptyDir:
            medium: Memory
        - name: web-env-volume
          configMap:
            name: web-config
        - name: web-tmp
          emptyDir:
            medium: Memory
{{- end -}}