apiVersion: apps/v1
kind: Deployment
metadata:
  name: next-gen-main
  namespace: nextgen
spec:
  replicas: 1
  selector:
    matchLabels:
      app: next-gen-main
  template:
    metadata:
      labels:
        app: next-gen-main
    spec:
      nodeName: vmi2853337
      containers:
        - name: app
          image: node:20-slim
          command: ["sh", "-c", "cd /app/server && node src/database/init.js && node src/index.js"]
          workingDir: /app
          env:
            - name: NODE_ENV
              value: "production"
            - name: PORT
              value: "3001"
            - name: DB_PATH
              value: "/app/data/school.db"
            - name: JWT_SECRET
              value: "africa-alert-production-secret-2024"
            - name: ALLOWED_ORIGINS
              value: "https://main.next-gen.techarvest.co.zw,https://next-gen.techarvest.co.zw,http://localhost:3000"
          ports:
            - name: http
              containerPort: 3001
          volumeMounts:
            - name: app-source
              mountPath: /app
      volumes:
        - name: app-source
          hostPath:
            path: /root/geocrop/apps/nextgen-main
            type: Directory
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: next-gen-dev
  namespace: nextgen
spec:
  replicas: 1
  selector:
    matchLabels:
      app: next-gen-dev
  template:
    metadata:
      labels:
        app: next-gen-dev
    spec:
      nodeName: vmi2853337
      containers:
        - name: app
          image: node:20-slim
          command: ["sh", "-c", "cd /app/server && node src/database/init.js && node src/index.js"]
          workingDir: /app
          env:
            - name: NODE_ENV
              value: "production"
            - name: PORT
              value: "3001"
            - name: DB_PATH
              value: "/app/data/school.db"
            - name: JWT_SECRET
              value: "africa-alert-dev-secret-2024"
            - name: ALLOWED_ORIGINS
              value: "https://dev.next-gen.techarvest.co.zw,http://localhost:3000"
          ports:
            - name: http
              containerPort: 3001
          volumeMounts:
            - name: app-source
              mountPath: /app
      volumes:
        - name: app-source
          hostPath:
            path: /root/geocrop/apps/nextgen-dev
            type: Directory
---
apiVersion: v1
kind: Service
metadata:
  name: next-gen-dev
  namespace: nextgen
spec:
  selector:
    app: next-gen-dev
  ports:
    - name: http
      protocol: TCP
      port: 80
      targetPort: 3001
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: next-gen-dev
  namespace: nextgen
  annotations:
    cert-manager.io/cluster-issuer: "letsencrypt-prod"
    nginx.ingress.kubernetes.io/proxy-body-size: "100m"
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/force-ssl-redirect: "false"
spec:
  ingressClassName: nginx
  tls:
    - hosts:
        - dev.next-gen.techarvest.co.zw
      secretName: next-gen-dev-tls
  rules:
    - host: dev.next-gen.techarvest.co.zw
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: next-gen-dev
                port:
                  number: 80
---
apiVersion: v1
kind: Service
metadata:
  name: next-gen-main
  namespace: nextgen
spec:
  selector:
    app: next-gen-main
  ports:
    - name: http
      protocol: TCP
      port: 80
      targetPort: 3001
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: next-gen-main
  namespace: nextgen
  annotations:
    cert-manager.io/cluster-issuer: "letsencrypt-prod"
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/force-ssl-redirect: "false"
spec:
  ingressClassName: nginx
  tls:
    - hosts:
        - main.next-gen.techarvest.co.zw
        - next-gen.techarvest.co.zw
      secretName: next-gen-main-tls
  rules:
    - host: main.next-gen.techarvest.co.zw
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: next-gen-main
                port:
                  number: 80
    - host: next-gen.techarvest.co.zw
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: next-gen-main
                port:
                  number: 80
