apiVersion: apps/v1
kind: Deployment
metadata:
  name: cameleer-server
spec:
  replicas: 1
  selector:
    matchLabels:
      app: cameleer-server
  template:
    metadata:
      labels:
        app: cameleer-server
    spec:
      imagePullSecrets:
        - name: gitea-registry
      securityContext:
        runAsNonRoot: true
        runAsUser: 1000
      containers:
        - name: server
          image: gitea.siegeln.net/cameleer/cameleer-server:latest
          ports:
            - containerPort: 8081
          env:
            - name: CAMELEER_SERVER_TENANT_ID
              value: "default"
            - name: SPRING_DATASOURCE_USERNAME
              valueFrom:
                secretKeyRef:
                  name: cameleer-postgres-credentials
                  key: POSTGRES_USER
            - name: SPRING_DATASOURCE_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: cameleer-postgres-credentials
                  key: POSTGRES_PASSWORD
            - name: SPRING_FLYWAY_USER
              valueFrom:
                secretKeyRef:
                  name: cameleer-postgres-credentials
                  key: POSTGRES_USER
            - name: SPRING_FLYWAY_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: cameleer-postgres-credentials
                  key: POSTGRES_PASSWORD
            - name: CAMELEER_SERVER_SECURITY_BOOTSTRAPTOKEN
              valueFrom:
                secretKeyRef:
                  name: cameleer-auth
                  key: CAMELEER_SERVER_SECURITY_BOOTSTRAPTOKEN
            - name: CAMELEER_SERVER_SECURITY_UIUSER
              valueFrom:
                secretKeyRef:
                  name: cameleer-auth
                  key: CAMELEER_SERVER_SECURITY_UIUSER
                  optional: true
            - name: CAMELEER_SERVER_SECURITY_UIPASSWORD
              valueFrom:
                secretKeyRef:
                  name: cameleer-auth
                  key: CAMELEER_SERVER_SECURITY_UIPASSWORD
                  optional: true
            - name: CAMELEER_SERVER_SECURITY_UIORIGIN
              value: "http://localhost:5173"
            - name: CAMELEER_SERVER_SECURITY_JWTSECRET
              valueFrom:
                secretKeyRef:
                  name: cameleer-auth
                  key: CAMELEER_SERVER_SECURITY_JWTSECRET
                  optional: true
            - name: CAMELEER_SERVER_CLICKHOUSE_URL
              value: "jdbc:clickhouse://cameleer-clickhouse.cameleer.svc.cluster.local:8123/cameleer"
            - name: CAMELEER_SERVER_CLICKHOUSE_USERNAME
              valueFrom:
                secretKeyRef:
                  name: cameleer-clickhouse-credentials
                  key: CLICKHOUSE_USER
            - name: CAMELEER_SERVER_CLICKHOUSE_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: cameleer-clickhouse-credentials
                  key: CLICKHOUSE_PASSWORD

          resources:
            requests:
              memory: "256Mi"
              cpu: "100m"
            limits:
              memory: "512Mi"
              cpu: "500m"
          livenessProbe:
            httpGet:
              path: /api/v1/health
              port: 8081
            initialDelaySeconds: 30
            periodSeconds: 10
            timeoutSeconds: 3
            failureThreshold: 3
          readinessProbe:
            httpGet:
              path: /api/v1/health
              port: 8081
            initialDelaySeconds: 10
            periodSeconds: 5
            timeoutSeconds: 3
            failureThreshold: 3
---
apiVersion: v1
kind: Service
metadata:
  name: cameleer-server
spec:
  type: ClusterIP
  selector:
    app: cameleer-server
  ports:
    - port: 8081
      targetPort: 8081
