apiVersion: apps/v1
kind: Deployment
metadata:
  name: gmail-agent
  namespace: ai-agents
  labels:
    app: gmail-agent
spec:
  replicas: 1
  selector:
    matchLabels:
      app: gmail-agent
  template:
    metadata:
      labels:
        app: gmail-agent
    spec:
      initContainers:
        - name: git-clone
          image: alpine/git
          command:
            - git
            - clone
            - http://192.168.8.248:3000/deepkoluguri/agentic-os.git
            - /app
          volumeMounts:
            - name: app-volume
              mountPath: /app
      containers:
        - name: gmail-agent
          image: node:18-alpine
          workingDir: /app/gmail-agent
          command:
            - sh
            - -c
            - npm install --omit=dev && node index.js
          env:
            - name: OLLAMA_URL
              value: http://ollama.ai-agents.svc.cluster.local:11434/api/generate
            - name: WHATSAPP_GATEWAY_URL
              value: http://whatsapp-gateway.ai-agents.svc.cluster.local:5001/api/send-message
            - name: WHATSAPP_TO
              value: "+14085505485"
            - name: OLLAMA_MODEL
              value: "qwen2.5:0.5b"
          volumeMounts:
            - name: app-volume
              mountPath: /app
            - name: credentials-volume
              mountPath: /app/gmail-agent/credentials.json
              subPath: credentials.json
              readOnly: true
            - name: tokens-volume
              mountPath: /app/gmail-agent/tokens
              readOnly: true
          ports:
            - containerPort: 5002
          resources:
            requests:
              cpu: 50m
              memory: 64Mi
            limits:
              cpu: 200m
              memory: 128Mi
      volumes:
        - name: app-volume
          emptyDir: {}
        - name: credentials-volume
          secret:
            secretName: gmail-agent-auth
            optional: true
            items:
              - key: credentials.json
                path: credentials.json
        - name: tokens-volume
          secret:
            secretName: gmail-agent-tokens
            optional: true

---
apiVersion: v1
kind: Service
metadata:
  name: gmail-agent
  namespace: ai-agents
spec:
  ports:
    - port: 5002
      targetPort: 5002
  selector:
    app: gmail-agent
