apiVersion: apps/v1
kind: Deployment
metadata:
  name: camunda-server
  labels:
    app: camunda-server
  namespace: camunda
spec:
  replicas: 1
  selector:
    matchLabels:
      app: camunda-server
  template:
    metadata:
      labels:
        app: camunda-server
    spec:
      containers:
        - name: camunda-server
          # En caso necesario cambiar endpoint de imagen
          image: gcr.io/poc-full-hybrid-264520/camunda-bpm-platform:latest
          ports:
            - containerPort: 8080
          env:
            - name: DB_DRIVER
              valueFrom:
                configMapKeyRef:
                  key: DB_DRIVER
                  name: camunda-server-configmap
            - name: DB_URL
              valueFrom:
                configMapKeyRef:
                  key: DB_URL
                  name: camunda-server-configmap
            - name: DEBUG
              valueFrom:
                configMapKeyRef:
                  key: DEBUG
                  name: camunda-server-configmap
            - name: JMX_PROMETHEUS
              valueFrom:
                configMapKeyRef:
                  key: JMX_PROMETHEUS
                  name: camunda-server-configmap
            - name: DB_VALIDATE_ON_BORROW
              valueFrom:
                configMapKeyRef:
                  key: DB_VALIDATE_ON_BORROW
                  name: camunda-server-configmap
            - name: DB_USERNAME
              valueFrom:
                secretKeyRef:
                  name: cloudsql-db-credentials
                  key: username
            - name: DB_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: cloudsql-db-credentials
                  key: password
        - name: cloudsql-proxy
          image: gcr.io/cloudsql-docker/gce-proxy:1.14
          # Cambiar la URL de la instancia SQL
          command: ["/cloud_sql_proxy",
                    "-instances=poc-full-hybrid-264520:us-central1:poc-fh-camunda-db=tcp:5432",
                    "-credential_file=/secrets/cloudsql/credentials.json"]
          securityContext:
            runAsUser: 2
            allowPrivilegeEscalation: false
          volumeMounts:
            - name: cloudsql-instance-credentials
              mountPath: /secrets/cloudsql
              readOnly: true
      volumes:
        - name: cloudsql-instance-credentials
          secret:
            secretName: cloudsql-instance-credentials
