apiVersion: apps/v1
kind: Deployment
metadata:
  name: mongo-${NAME}
  labels:
    deploy-name: "${NAME}"
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mongo-${NAME}
  template:
    metadata:
      labels:
        app: mongo-${NAME}
        deploy-name: "${NAME}"
    spec:
      containers:
        - name: mongo
          image: mongo:8
          ports:
            - containerPort: 27017
          env:
            - name: MONGO_INITDB_ROOT_USERNAME
              value: "root"
            - name: MONGO_INITDB_ROOT_PASSWORD
              value: "mongoose"

---

apiVersion: v1
kind: Service
metadata:
  name: mongo-${NAME}
  labels:
    deploy-name: "${NAME}"
spec:
  selector:
    app: mongo-${NAME}
  ports:
    - port: 27017

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: calchat-server-${NAME}
  labels:
    deploy-name: "${NAME}"
spec:
  replicas: 1
  selector:
    matchLabels:
      app: calchat-server-${NAME}
  template:
    metadata:
      labels:
        app: calchat-server-${NAME}
        deploy-name: "${NAME}"
    spec:
      containers:
        - name: calchat-server
          image: gitea.gilmour109.de/gilmour109/calchat-server:${TAG}
          imagePullPolicy: Always
          ports:
            - containerPort: 3001
          env:
            - name: PORT
              value: "3001"
            - name: MONGODB_URI
              value: "mongodb://root:mongoose@mongo-${NAME}:27017/calchat?authSource=admin"
            - name: USE_TEST_RESPONSES
              value: "true"
            - name: VERSION
              value: "${TAG}"
            - name: COMMIT
              value: "${COMMIT}"
            - name: OPENAI_API_KEY
              value: "dummy"

---

apiVersion: v1
kind: Service
metadata:
  name: calchat-server-${NAME}
  labels:
    deploy-name: "${NAME}"
spec:
  selector:
    app: calchat-server-${NAME}
  ports:
    - port: 3001

---

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: calchat-server-${NAME}
  labels:
    deploy-name: "${NAME}"
spec:
  rules:
  - host: "${NAME}.192.168.178.201.nip.io"
    http:
      paths:
      - pathType: Prefix
        path: "/"
        backend:
          service:
            name: calchat-server-${NAME}
            port:
              number: 3001
