apiVersion: apps/v1
kind: Deployment
metadata:
  name: market-app
  namespace: ai-agents
spec:
  replicas: 1
  selector:
    matchLabels:
      app: market-app
  template:
    metadata:
      labels:
        app: market-app
    spec:
      containers:
      - name: market
        image: 192.168.8.250:5000/market:latest
        imagePullPolicy: Always
        ports:
        - containerPort: 3010
        env:
        - name: NODE_ENV
          value: "production"
        - name: CORS_ORIGIN
          value: "https://market.applaude.net"
        - name: USE_PYTHON_SERVICE
          value: "false"
        - name: DATABASE_URL
          valueFrom:
            secretKeyRef:
              name: market-db-app
              key: uri
        livenessProbe:
          tcpSocket:
            port: 3010
          initialDelaySeconds: 15
          periodSeconds: 20
          failureThreshold: 5
        readinessProbe:
          tcpSocket:
            port: 3010
          initialDelaySeconds: 10
          periodSeconds: 10
          failureThreshold: 3
      - name: python-service
        image: python:3.11-slim
        command: ['sh', '-c', 'pip install --no-cache-dir -r requirements.txt && uvicorn main:app --host 0.0.0.0 --port 8010']
        workingDir: /shared-code
        ports:
        - containerPort: 8010
        env:
        - name: USE_LOCAL_DB
          value: "true"
        - name: LOCAL_DB_HOST
          value: "192.168.8.151"
        - name: LOCAL_DB_PORT
          value: "5432"
        - name: LOCAL_DB_USER
          value: "postgres"
        - name: LOCAL_DB_PASSWORD
          value: "postgres"
        - name: LOCAL_DB_NAME
          value: "institutional_trader"
        volumeMounts:
        - name: shared-code
          mountPath: /shared-code
      initContainers:
      - name: copy-python-code
        image: 192.168.8.250:5000/market:latest
        command: ['sh', '-c', 'cp -r /app/backend/python_service/* /shared-code/']
        volumeMounts:
        - name: shared-code
          mountPath: /shared-code
      volumes:
      - name: shared-code
        emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
  name: market-app
  namespace: ai-agents
spec:
  selector:
    app: market-app
  ports:
  - port: 80
    targetPort: 3010
