---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: news-scan-pvc
  namespace: ai-agents
spec:
  accessModes: [ReadWriteOnce]
  storageClassName: longhorn
  resources:
    requests:
      storage: 10Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: news-scan
  namespace: ai-agents
  labels:
    app: news-scan
spec:
  replicas: 1
  selector:
    matchLabels:
      app: news-scan
  template:
    metadata:
      labels:
        app: news-scan
    spec:
      initContainers:
        - name: git-clone
          image: alpine/git
          command:
            - git
            - clone
            - http://192.168.8.248:3000/deepkoluguri/sundeep-news-scan.git
            - /app
          volumeMounts:
            - name: app-code
              mountPath: /app
      containers:
        - name: news-scan
          image: python:3.11-slim
          workingDir: /app
          command:
            - sh
            - -c
            - |
              apt-get update && apt-get install -y libgl1 libglib2.0-0 tesseract-ocr tesseract-ocr-tel
              pip install -r requirements.txt gunicorn
              # Create symlinks so app writes to PVC
              mkdir -p /data/uploads /data/output
              rm -rf /app/uploads /app/output
              ln -s /data/uploads /app/uploads
              ln -s /data/output /app/output
              # Run the web server
              gunicorn --bind 0.0.0.0:5000 app:app --timeout 600
          ports:
            - containerPort: 5000
          env:
            - name: PYTHONUNBUFFERED
              value: "1"
            # --- Google Drive Sync Placeholders ---
            - name: ENABLE_GDRIVE_SYNC
              value: "false" # Set to "true" to enable
            - name: GDRIVE_CREDENTIALS_JSON
              value: ""      # Placeholder for service account JSON
            - name: GDRIVE_FOLDER_ID
              value: ""      # Placeholder for target Google Drive folder ID
          volumeMounts:
            - name: app-code
              mountPath: /app
            - name: data-volume
              mountPath: /data
          resources:
            requests:
              cpu: 500m
              memory: 1Gi
            limits:
              cpu: 2000m
              memory: 4Gi
      volumes:
        - name: app-code
          emptyDir: {}
        - name: data-volume
          persistentVolumeClaim:
            claimName: news-scan-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: news-scan
  namespace: ai-agents
spec:
  selector:
    app: news-scan
  ports:
    - port: 5000
      targetPort: 5000
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: news-scan-ingress
  namespace: ai-agents
  annotations:
    k8s.apisix.apache.org/proxy-timeout-connect: "300s"
    k8s.apisix.apache.org/proxy-timeout-read: "300s"
    k8s.apisix.apache.org/proxy-timeout-send: "300s"
    k8s.apisix.apache.org/plugin-config-name: news-scan-plugins
spec:
  ingressClassName: apisix
  rules:
  - host: newsupdate.applaude.net
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: news-scan
            port:
              number: 5000
---
apiVersion: apisix.apache.org/v2
kind: ApisixPluginConfig
metadata:
  name: news-scan-plugins
  namespace: ai-agents
spec:
  plugins:
  - name: client-control
    enable: true
    config:
      max_body_size: 209715200
