apiVersion: apps/v1
kind: Deployment

metadata:
  namespace: singouins-dev
  name: sep-backend-api
  labels:
    tier: sep-backend
spec:
  replicas: 1
  selector:
    matchLabels:
      app: api
      tier: sep-backend
  strategy:
    type: Recreate
  template:
    metadata:
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "5000"
      labels:
        app: api
        tier: sep-backend
    spec:
      restartPolicy: Always

      containers:
      - name: sep-backend-api
#        command: ["/bin/sh"]
#        args: ["-c", "while :; do sleep 12h; done;"]
        image: lordslair/api:dev
        imagePullPolicy: Always
        resources:
          limits:
            memory: 256Mi
            cpu: 500m
          requests:
            memory: 128Mi
            cpu: 50m
        env:
        #  Enable debug mode is set to 'development'
        - name: FLASK_ENV
          value: 'development'
        # Gunicorn env vars
        - name: GUNICORN_HOST
          value: '0.0.0.0'
        - name: GUNICORN_PORT
          value: '5000'
        - name: GUNICORN_WORKERS
          value: '1'
        - name: GUNICORN_THREADS
          value: '2'
        - name: GUNICORN_RELOAD
          value: '--reload'
        # App variables
        - name: SEP_REDIS_DB
          valueFrom:
            secretKeyRef:
              name: sep-backend-redis-secret
              key: redis-base
        - name: SEP_INTERNAL_TOKEN
          valueFrom:
            secretKeyRef:
              name: sep-backend-api-secret
              key: api-internal-token
        - name: SEP_API_URL
          valueFrom:
            secretKeyRef:
              name: sep-backend-api-secret
              key: api-url
        - name: SEP_SECRET_KEY
          valueFrom:
            secretKeyRef:
              name: sep-backend-api-secret
              key: jwt-secret
        # MySQL variables
        - name: SEP_MYSQL_USER
          valueFrom:
            secretKeyRef:
              name: sep-backend-api-secret
              key: sql-user
        - name: SEP_MYSQL_PASSWORD
          valueFrom:
            secretKeyRef:
              name: sep-backend-api-secret
              key: sql-pass
        - name: SEP_MYSQL_DB
          valueFrom:
            secretKeyRef:
              name: sep-backend-api-secret
              key: sql-base
        - name: SEP_MYSQL_HOST
          valueFrom:
            secretKeyRef:
              name: sep-backend-mariadb-secret
              key: mariadb-host
        - name: SEP_MYSQL_PORT
          valueFrom:
            secretKeyRef:
              name: sep-backend-mariadb-secret
              key: mariadb-port
        # SMTP variables
        - name: SEP_SMTP_FROM
          valueFrom:
            secretKeyRef:
              name: sep-backend-smtp-secret
              key: smtp-from
        - name: SEP_SMTP_SERVER
          valueFrom:
            secretKeyRef:
              name: sep-backend-smtp-secret
              key: smtp-server
        - name: SEP_SMTP_USER
          valueFrom:
            secretKeyRef:
              name: sep-backend-smtp-secret
              key: smtp-user
        - name: SEP_SMTP_PASS
          valueFrom:
            secretKeyRef:
              name: sep-backend-smtp-secret
              key: smtp-pass
        - name: SEP_SMTP_HOSTNAME
          valueFrom:
            secretKeyRef:
              name: sep-backend-smtp-secret
              key: smtp-host
        # PCS variables
        - name: SEP_PCS_URL
          valueFrom:
            secretKeyRef:
              name: sep-backend-pcs-secret
              key: pcs-public-url
        # Discord variables
        - name: SEP_DISCORD_URL
          valueFrom:
            secretKeyRef:
              name: sep-backend-discord-secret
              key: invite-url
        # LDP variables
        - name: SEP_LDP_HOST
          value: '2'
        - name: SEP_LDP_TOKEN
          value: '2'
