apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Release.Name }}
  labels:
    app: {{ .Release.Name }}
    branch: {{ .Values.branchName }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app: {{ .Release.Name }}
    spec:
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          command:
            - sh
            - -c
            - "mkdir -p /app/data && node src/database/init.js && node src/index.js"
          ports:
            - name: http
              containerPort: {{ .Values.service.port }}
              protocol: TCP
          env:
            - name: PORT
              value: "{{ .Values.service.port }}"
            - name: NODE_ENV
              value: "production"
            - name: DB_PATH
              value: "/app/data/school.db"
            - name: JWT_SECRET
              value: "africa-alert-production-secret-2024"
          resources:
            {{- toYaml .Values.resources | nindent 12 }}

