apiVersion: apps/v1
kind: Deployment
metadata:
  name: api-headless
  labels:
    app: api-headless
spec:
  replicas: 1
  selector:
    matchLabels:
      app: api-headless
  template:
    metadata:
      labels:
        app: api-headless
    spec:
      initContainers:
        - name: migrate-database
          image: ghcr.io/podkrepi-bg/api/migrations
          imagePullPolicy: Always
          env:
            - name: NODE_ENV
              value: production
            - name: DATABASE_URL
              valueFrom:
                secretKeyRef:
                  name: db-api
                  key: url
      containers:
        - name: api-headless
          image: ghcr.io/podkrepi-bg/api
          imagePullPolicy: Always
          resources:
            limits:
              memory: 512Mi
              cpu: '1'
            requests:
              memory: 256Mi
              cpu: '0.2'
          ports:
            - containerPort: 80
          livenessProbe:
            httpGet:
              path: /api/health
              port: 80
            initialDelaySeconds: 10
            periodSeconds: 5
          readinessProbe:
            httpGet:
              path: /api/health
              port: 80
            initialDelaySeconds: 5
            periodSeconds: 5
          env:
            - name: NODE_ENV
              value: production
            - name: PORT
              value: '80'
            - name: TARGET_APP
              value: api
            - name: DATABASE_URL
              valueFrom:
                secretKeyRef:
                  name: db-api
                  key: url
            - name: KEYCLOAK_URL
              valueFrom:
                configMapKeyRef:
                  name: keycloak-config
                  key: url
            - name: KEYCLOAK_REALM
              valueFrom:
                configMapKeyRef:
                  name: keycloak-config
                  key: realm
            - name: KEYCLOAK_CLIENT_ID
              valueFrom:
                configMapKeyRef:
                  name: keycloak-config
                  key: client-id
            - name: KEYCLOAK_SECRET
              valueFrom:
                secretKeyRef:
                  name: keycloak-secret
                  key: secret
            - name: STRIPE_SECRET_KEY
              valueFrom:
                secretKeyRef:
                  name: stripe-secret
                  key: apikey
            - name: STRIPE_WEBHOOK_SECRET
              valueFrom:
                secretKeyRef:
                  name: stripe-secret
                  key: webhookSecret
            - name: SENDGRID_SENDER_EMAIL
              valueFrom:
                configMapKeyRef:
                  name: sendgrid-config
                  key: sender-email
            - name: SENDGRID_INTERNAL_EMAIL
              valueFrom:
                configMapKeyRef:
                  name: sendgrid-config
                  key: internal-notifications-email
            - name: SENDGRID_API_KEY
              valueFrom:
                secretKeyRef:
                  name: sendgrid-secret
                  key: apikey
            - name: SENTRY_DSN
              valueFrom:
                configMapKeyRef:
                  name: sentry-config
                  key: dsn-api
            - name: SENTRY_ORG
              valueFrom:
                configMapKeyRef:
                  name: sentry-config
                  key: org
            - name: SENTRY_PROJECT
              valueFrom:
                configMapKeyRef:
                  name: sentry-config
                  key: project-api
            - name: SENTRY_AUTH_TOKEN
              value: ''
            - name: SENTRY_SERVER_ROOT_DIR
              valueFrom:
                configMapKeyRef:
                  name: sentry-config
                  key: server-root-dir
