apiVersion: apps/v1
kind: Deployment
metadata:
  name: sco-bot
spec:
  replicas: 1
  strategy: {type: Recreate}
  selector:
    matchLabels:
      app: sco-bot
  template:
    metadata:
      labels:
        app: sco-bot
    spec:
      volumes:
        - name: sco-bot-data
          persistentVolumeClaim:
            claimName: sco-bot-data
      containers:
        - name: vite
          image: reg:5000/sco_bot_web
          workingDir: /opt
          command:
            - pnpm
            - exec
            - vite
          ports:
            - containerPort: 8002
              name: web

        - name: search-server
          image: reg:5000/sco_bot_server
          securityContext: { runAsUser: 1020 }
          workingDir: /opt
          command:
            - pdm
            - run
            - fastapi
            - dev
            - --host
            - "0.0.0.0"
            - --port
            - "8001"
            - scobot
          ports:
            - containerPort: 8001
              name: server
          volumeMounts:
            - name: sco-bot-data
              mountPath: /opt/data

        - name: prefect-db
          securityContext:
            runAsUser: 70 # = postgres user, needed to write to /var/run in the container
          image: postgres:16.3-alpine
          env:
            - { name: PGDATA, value: /opt/data/postgres/data }
            - { name: POSTGRES_USER, value: postgres }
            - { name: POSTGRES_PASSWORD, value: admin }
            - { name: POSTGRES_DB, value: prefect }
          ports:
            - containerPort: 5432
          volumeMounts:
            - name: sco-bot-data
              mountPath: /opt/data

        - name: prefect
          image: reg:5000/sco_bot_server
          securityContext: { runAsUser: 1020 }
          workingDir: /opt
          env:
            - name: PREFECT_API_URL
              value: https://sco-bot-prefect.bigasterisk.com/api
            - name: PREFECT_API_DATABASE_CONNECTION_URL
              value: "postgresql+asyncpg://postgres:admin@localhost:5432/prefect"
          command:
            - pdm
            - run_prefect_server
          ports:
            - containerPort: 4200
              name: prefect
          volumeMounts:
            - name: sco-bot-data
              mountPath: /opt/data

        - name: build-flow
          image: reg:5000/sco_bot_server
          securityContext: { runAsUser: 1020 }
          workingDir: /opt
          env:
            - name: PREFECT_API_URL
              value: http://localhost:4200/api
            - name: PREFECT_API_DATABASE_CONNECTION_URL
              value: "postgresql+asyncpg://postgres:admin@localhost:5432/prefect"
          command:
            - pdm
            - run_build_flow
          volumeMounts:
            - name: sco-bot-data
              mountPath: /opt/data

      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                  - key: "kubernetes.io/hostname"
                    operator: In
                    values: ["ditto", "dash"] # need /my/serv
