apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "firecrawl.fullname" . }}-api
  labels:
    app: {{ include "firecrawl.name" . }}-api
spec:
  replicas: {{ .Values.api.replicaCount | default .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ include "firecrawl.name" . }}-api
  template:
    metadata:
      labels:
        app: {{ include "firecrawl.name" . }}-api
    spec:
      {{- if .Values.image.dockerSecretEnabled }}
      imagePullSecrets:
        {{- toYaml .Values.imagePullSecrets | nindent 8 }}
      {{- end }}
      terminationGracePeriodSeconds: 180
      containers:
        - name: api
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          command: [ "node" ]
          args: [ "--max-old-space-size=6144", "dist/src/index.js" ]
          ports:
            - containerPort: {{ .Values.service.api.port }}
          env:
            - name: FLY_PROCESS_GROUP
              value: "app"
            - name: NUQ_POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
          envFrom:
            - configMapRef:
                name: {{ include "firecrawl.fullname" . }}-config
            - secretRef:
                name: {{ include "firecrawl.fullname" . }}-secret
          {{- if and .Values.resources.enabled .Values.api.resources }}
          resources:
            {{- toYaml .Values.api.resources | nindent 12 }}
          {{- end }}
          livenessProbe:
            httpGet:
              path: /v0/health/liveness
              port: {{ .Values.service.api.port }}
            initialDelaySeconds: 30
            periodSeconds: 30
            timeoutSeconds: 5
            successThreshold: 1
            failureThreshold: 3
          readinessProbe:
            httpGet:
              path: /v0/health/readiness
              port: {{ .Values.service.api.port }}
            initialDelaySeconds: 30
            periodSeconds: 30
            timeoutSeconds: 5
            successThreshold: 1
            failureThreshold: 3
