apiVersion: apps/v1
kind: Deployment
metadata:
  name: jobrunner
  labels:
    app: jobrunner
spec:
  replicas: 1
  selector:
    matchLabels:
      app: jobrunner
  template:
    metadata:
      labels:
        app: jobrunner
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "3000"
        prometheus.io/path: "/api/health/"
    spec:
      containers:
      - name: jobrunner
        image: gsatspencer/identity-idp
        command: ["/usr/local/bin/bundle"]
        args: ["exec", "rake", "job_runs:run[/tmp/job_runs.pid]"]
        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-config
              key: db_hostname
        - name: domain_name
          valueFrom:
            configMapKeyRef:
              name: idp-config
              key: domain_name
        - name: mailer_domain_name
          valueFrom:
            configMapKeyRef:
              name: idp-config
              key: mailer_domain_name
        - name: asset_host
          valueFrom:
            configMapKeyRef:
              name: idp-config
              key: mailer_domain_name
        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
