---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: uro-deployment
  namespace: default
  labels:
    app: uro
spec:
  replicas: 1
  selector:
    matchLabels:
      app: uro
  template:
    metadata:
      labels:
        app: uro
    spec:
      serviceAccountName: cockroachdb
      volumes:
      - name: client-certs
        emptyDir: {}
      - name: static01-storage
        persistentVolumeClaim:
          claimName: static01-pvc
      initContainers:
      # The init-certs container sends a certificate signing request to the
      # kubernetes cluster.
      # You can see pending requests using: kubectl get csr
      # CSRs can be approved using:         kubectl certificate approve <csr name>
      #
      # In addition to the client certificate and key, the init-certs entrypoint will symlink
      # the cluster CA to the certs directory.
      - name: init-certs
        image: cockroachdb/cockroach-k8s-request-cert:0.4
        imagePullPolicy: IfNotPresent
        command:
        - "/bin/ash"
        - "-ecx"
        - "/request-cert -namespace=${POD_NAMESPACE} -certs-dir=/cockroach-certs -type=client\
          \ -user=uro-prod -symlink-ca-from=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
        env:
        - name: POD_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        volumeMounts:
        - name: client-certs
          mountPath: /cockroach-certs
      containers:
      - name: uro
        env:
        - name: SENDGRID_API_KEY
          valueFrom:
            secretKeyRef:
              name: uro-prod
              key: sendgrid-api-key
        - name: DISCORD_CLIENT_ID
          valueFrom:
            secretKeyRef:
              name: uro-prod
              key: discord-client-id
        - name: DISCORD_CLIENT_SECRET
          valueFrom:
            secretKeyRef:
              name: uro-prod
              key: discord-client-secret
        - name: SECRET_KEY_BASE
          valueFrom:
            secretKeyRef:
              name: uro-prod
              key: secret-key-base
        - name: DATABASE_PASS
          valueFrom:
            secretKeyRef:
              name: uro-prod
              key: pass
        - name: DATABASE_URL
          value: "postgres://uro-prod@cockroachdb-public:26257/uro_prod?sslmode=verify-full&sslcert=/cockroach-certs/client.uro-prod.crt&sslkey=/cockroach-certs/client.uro-prod.key&sslrootcert=/cockroach-certs/ca.crt"
        image: groupsinfra/uro:autodocker
        imagePullPolicy: Always
        volumeMounts:
        - name: client-certs
          mountPath: /cockroach-certs
        - name: static01-storage
          mountPath: /app/uploads
          subPath: uploads
        ports:
        - containerPort: 4000
          name: http
      restartPolicy: Always
