apiVersion: apps/v1
kind: Deployment
metadata:
  name: iam-production
spec:
  selector:
    matchLabels:
      app: iam
      env: production
  replicas: 1
  template:
    metadata:
      labels:
        app: iam
        env: production
    spec:
      initContainers:
      - name: migrate
        image: gcr.io/dd-decaf-cfbf6/iam:master
        imagePullPolicy: Always
        env:
        - name: ENVIRONMENT
          value: production
        - name: SCRIPT_NAME
          value: /iam
        - name: FLASK_APP
          value: src/iam/wsgi.py
        - name: SECRET_KEY
          valueFrom:
            secretKeyRef:
              name: iam-production
              key: SECRET_KEY
        - name: ALLOWED_ORIGINS
          value: https://caffeine.dd-decaf.eu,https://staging.dd-decaf.eu,http://localhost:4200
        - name: SENTRY_DSN
          valueFrom:
            secretKeyRef:
              name: iam-production
              key: SENTRY_DSN
        - name: BASIC_AUTH_USERNAME
          valueFrom:
            secretKeyRef:
              name: iam-production
              key: BASIC_AUTH_USERNAME
        - name: BASIC_AUTH_PASSWORD
          valueFrom:
            secretKeyRef:
              name: iam-production
              key: BASIC_AUTH_PASSWORD
        - name: FEAT_TOGGLE_LOCAL_AUTH
          value: "1"
        - name: DB_HOST
          value: cloudsql-proxy
        - name: DB_PORT
          value: "5432"
        - name: DB_NAME
          value: iam_production
        - name: DB_USERNAME
          valueFrom:
            secretKeyRef:
              name: iam-production
              key: DB_USERNAME
        - name: DB_PASSWORD
          valueFrom:
            secretKeyRef:
              name: iam-production
              key: DB_PASSWORD
        - name: FEAT_TOGGLE_FIREBASE
          value: "1"
        - name: FIREBASE_PROJECT_ID
          value: dd-decaf-cfbf6
        - name: FIREBASE_CLIENT_CERT_URL
          valueFrom:
            secretKeyRef:
              name: iam-production
              key: FIREBASE_CLIENT_CERT_URL
        - name: FIREBASE_CLIENT_EMAIL
          valueFrom:
            secretKeyRef:
              name: iam-production
              key: FIREBASE_CLIENT_EMAIL
        - name: FIREBASE_CLIENT_ID
          valueFrom:
            secretKeyRef:
              name: iam-production
              key: FIREBASE_CLIENT_ID
        - name: FIREBASE_PRIVATE_KEY
          valueFrom:
            secretKeyRef:
              name: iam-production
              key: FIREBASE_PRIVATE_KEY
        - name: FIREBASE_PRIVATE_KEY_ID
          valueFrom:
            secretKeyRef:
              name: iam-production
              key: FIREBASE_PRIVATE_KEY_ID
        - name: prometheus_multiproc_dir
          value: /prometheus-client
        volumeMounts:
        - name: rsa
          mountPath: "/app/keys"
          readOnly: true
        command: ["flask", "db", "upgrade"]
        resources:
          requests:
            cpu: "1m"
          limits:
            cpu: "2000m"
      containers:
      - name: web
        image: gcr.io/dd-decaf-cfbf6/iam:master
        imagePullPolicy: Always
        ports:
        - containerPort: 8000
        env:
        - name: ENVIRONMENT
          value: production
        - name: SCRIPT_NAME
          value: /iam
        - name: FLASK_APP
          value: src/iam/wsgi.py
        - name: SECRET_KEY
          valueFrom:
            secretKeyRef:
              name: iam-production
              key: SECRET_KEY
        - name: ALLOWED_ORIGINS
          value: https://production.dd-decaf.eu,https://caffeine.dd-decaf.eu,http://localhost:4200
        - name: SENTRY_DSN
          valueFrom:
            secretKeyRef:
              name: iam-production
              key: SENTRY_DSN
        - name: BASIC_AUTH_USERNAME
          valueFrom:
            secretKeyRef:
              name: iam-production
              key: BASIC_AUTH_USERNAME
        - name: BASIC_AUTH_PASSWORD
          valueFrom:
            secretKeyRef:
              name: iam-production
              key: BASIC_AUTH_PASSWORD
        - name: FEAT_TOGGLE_LOCAL_AUTH
          value: "1"
        - name: DB_HOST
          value: cloudsql-proxy
        - name: DB_PORT
          value: "5432"
        - name: DB_NAME
          value: iam_production
        - name: DB_USERNAME
          valueFrom:
            secretKeyRef:
              name: iam-production
              key: DB_USERNAME
        - name: DB_PASSWORD
          valueFrom:
            secretKeyRef:
              name: iam-production
              key: DB_PASSWORD
        - name: FEAT_TOGGLE_FIREBASE
          value: "1"
        - name: FIREBASE_PROJECT_ID
          value: dd-decaf-cfbf6
        - name: FIREBASE_CLIENT_CERT_URL
          valueFrom:
            secretKeyRef:
              name: iam-production
              key: FIREBASE_CLIENT_CERT_URL
        - name: FIREBASE_CLIENT_EMAIL
          valueFrom:
            secretKeyRef:
              name: iam-production
              key: FIREBASE_CLIENT_EMAIL
        - name: FIREBASE_CLIENT_ID
          valueFrom:
            secretKeyRef:
              name: iam-production
              key: FIREBASE_CLIENT_ID
        - name: FIREBASE_PRIVATE_KEY
          valueFrom:
            secretKeyRef:
              name: iam-production
              key: FIREBASE_PRIVATE_KEY
        - name: FIREBASE_PRIVATE_KEY_ID
          valueFrom:
            secretKeyRef:
              name: iam-production
              key: FIREBASE_PRIVATE_KEY_ID
        - name: prometheus_multiproc_dir
          value: /prometheus-client
        - name: SENDGRID_API_KEY
          valueFrom:
            secretKeyRef:
              name: iam-production
              key: SENDGRID_API_KEY
        volumeMounts:
        - name: rsa
          mountPath: "/app/keys"
          readOnly: true
        - name: prometheus-client
          mountPath: /prometheus-client
        readinessProbe:
          httpGet:
            path: /iam/healthz
            port: 8000
          initialDelaySeconds: 5
        resources:
          requests:
            cpu: "1m"
          limits:
            cpu: "2000m"
      volumes:
      - name: rsa
        secret:
          secretName: iam-rsa-production
      - name: prometheus-client
        emptyDir: {}
