apiVersion: apps/v1
kind: Deployment
metadata:
  name: wcag-ada-api
  namespace: wcag-ada
spec:
  replicas: 3
  selector:
    matchLabels:
      app: wcag-ada-api
  template:
    metadata:
      labels:
        app: wcag-ada-api
    spec:
      initContainers:
      - name: wait-for-postgres
        image: busybox:1.36
        command: ['sh', '-c', 'until nc -z postgres-service 5432; do echo waiting for postgres; sleep 2; done']
      - name: run-migrations
        image: wcag-ada/api:latest
        command: ["bunx", "prisma", "migrate", "deploy"]
        envFrom:
        - configMapRef:
            name: wcag-ada-config
        - secretRef:
            name: wcag-ada-secrets
      containers:
      - name: api
        image: wcag-ada/api:latest
        ports:
        - containerPort: 3001
        envFrom:
        - configMapRef:
            name: wcag-ada-config
        - secretRef:
            name: wcag-ada-secrets
        livenessProbe:
          httpGet:
            path: /health
            port: 3001
          initialDelaySeconds: 30
          periodSeconds: 10
        readinessProbe:
          httpGet:
            path: /health
            port: 3001
          initialDelaySeconds: 5
          periodSeconds: 5
        resources:
          requests:
            memory: "256Mi"
            cpu: "100m"
          limits:
            memory: "512Mi"
            cpu: "500m"
---
apiVersion: v1
kind: Service
metadata:
  name: wcag-ada-api-service
  namespace: wcag-ada
spec:
  selector:
    app: wcag-ada-api
  ports:
    - port: 3001
      targetPort: 3001
  type: ClusterIP