apiVersion: apps/v1
kind: Deployment
metadata:
  name: idp
  labels:
    app: idp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: idp
  template:
    metadata:
      labels:
        app: idp
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "3000"
        prometheus.io/path: "/api/health/"
    spec:
      containers:
      - name: idp
        image: gsatspencer/identity-idp
        resources:
          requests:
            memory: "1024Mi"
            cpu: "1"
          limits:
            memory: "2048Mi"
            cpu: "2"
        env:
        - name: RAILS_SERVE_STATIC_FILES
          value: "true"
        - name: RAILS_ENV
          value: "production"
        - name: NEW_RELIC_AGENT_ENABLED
          value: "false"
        - name: database_host
          valueFrom:
            configMapKeyRef:
              name: idp-postgres
              key: hostname
        ports:
        - containerPort: 3000
        volumeMounts:
        - name: appconfig
          mountPath: "/appconfig"
          readOnly: true
        - name: certs
          mountPath: "/upaya/certs"
          readOnly: true
        - name: keys
          mountPath: "/upaya/keys"
          readOnly: true
        lifecycle:
          postStart:
            exec:
              command:
                - /bin/sh
                - -c
                - |
                  /bin/bash <<'EOF'
                  # This copies in all of the secrets/config since k8s can't mount files like docker does
                  # Ideally, config would be passed in as env vars, but that seems like a PITA to translate over.
                  cp /appconfig/application.yml /upaya/config/
                  cp /appconfig/agencies.yml /upaya/config/
                  cp /appconfig/service_providers.yml /upaya/config/
                  cp /appconfig/pwned_passwords.txt /upaya/pwned_passwords/
                  EOF
      volumes:
      - name: appconfig
        secret:
          secretName: appconfig
      - name: certs
        secret:
          secretName: certs
      - name: keys
        secret:
          secretName: keys
