apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: whatsapp-auth-pvc
  namespace: ai-agents
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
  storageClassName: longhorn
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: whatsapp-gateway
  namespace: ai-agents
  labels:
    app: whatsapp-gateway
spec:
  replicas: 1
  selector:
    matchLabels:
      app: whatsapp-gateway
  template:
    metadata:
      labels:
        app: whatsapp-gateway
    spec:
      serviceAccountName: default
      initContainers:
        - name: git-clone
          image: alpine/git
          command:
            - "sh"
            - "-c"
            - "git clone http://192.168.8.248:3000/deepkoluguri/agentic-os.git /workspace && cp -r /workspace/whatsapp-gateway/* /app/"
          volumeMounts:
            - name: app-code
              mountPath: /app
      containers:
        - name: whatsapp-gateway
          image: node:18
          command:
            - "sh"
            - "-c"
            - "apt-get update && apt-get install -y libnss3 libnspr4 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libgbm1 libasound2 && cd /app && npm install && node server.js"
          volumeMounts:
            - name: app-code
              mountPath: /app
            - name: dshm
              mountPath: /dev/shm
            - name: auth-session
              mountPath: /app/.wwebjs_auth
          ports:
            - containerPort: 5001
          resources:
            requests:
              cpu: 300m
              memory: 768Mi
            limits:
              cpu: "2"
              memory: 2Gi
      volumes:
        - name: app-code
          emptyDir: {}
        - name: dshm
          emptyDir:
            medium: Memory
            sizeLimit: 1Gi
        - name: auth-session
          persistentVolumeClaim:
            claimName: whatsapp-auth-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: whatsapp-gateway
  namespace: ai-agents
spec:
  ports:
    - port: 5001
      targetPort: 5001
  selector:
    app: whatsapp-gateway
