---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: obs
spec:
  selector:
    matchLabels:
      app: obs-server
  replicas: 1
  template:
    metadata:
      labels:
        app: obs-server
    spec:
      containers:

      # obs also has a webserver
      - name: obs
        image: adanalife/obs:latest
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 8080
        - containerPort: 5900
        # readinessProbe:
        #   httpGet:
        #     path: /health/ready
        #     port: 80
        #   initialDelaySeconds: 30
        #   periodSeconds: 10
        #   timeoutSeconds: 3
        #   failureThreshold: 1
        # livenessProbe:
        #   httpGet:
        #     path: /health/live
        #     port: 80
        #   initialDelaySeconds: 60
        #   periodSeconds: 10
        #   timeoutSeconds: 3
        #   failureThreshold: 1
        resources:
          requests:
            memory: 128Mi
            cpu: 2
            ephemeral-storage: 1Gi
          limits:
            memory: 256Mi
            cpu: 2
        env:
         - name: DATABASE_HOST
           valueFrom:
             secretKeyRef:
               name: tripbot-secrets
               key: DATABASE_HOST
         - name: DATABASE_DB
           valueFrom:
             secretKeyRef:
               name: tripbot-secrets
               key: DATABASE_DB
         - name: DATABASE_USER
           valueFrom:
             secretKeyRef:
               name: tripbot-secrets
               key: DATABASE_USER
         - name: DATABASE_HOST
           valueFrom:
             secretKeyRef:
               name: tripbot-secrets
               key: DATABASE_HOST
         - name: TWITCH_CLIENT_ID
           valueFrom:
             secretKeyRef:
               name: tripbot-secrets
               key: TWITCH_CLIENT_ID
         - name: TWITCH_CLIENT_SECRET
           valueFrom:
             secretKeyRef:
               name: tripbot-secrets
               key: TWITCH_CLIENT_SECRET
         - name: TWITCH_AUTH_TOKEN
           valueFrom:
             secretKeyRef:
               name: tripbot-secrets
               key: TWITCH_AUTH_TOKEN
         - name: SENTRY_DSN
           valueFrom:
             secretKeyRef:
               name: tripbot-secrets
               key: SENTRY_DSN
         - name: TRIPBOT_HTTP_AUTH
           valueFrom:
             secretKeyRef:
               name: tripbot-secrets
               key: TRIPBOT_HTTP_AUTH
         - name: TWILIO_AUTH_TOKEN
           valueFrom:
             secretKeyRef:
               name: tripbot-secrets
               key: TWILIO_AUTH_TOKEN

        volumeMounts:
        # mount dashcam folder
        - name: dashcam-volume
          mountPath: /opt/data/Dashcam/_all
        # mount google-creds secret
        # - name: google-creds
        #   mountPath: /opt/tripbot/infra/google
        #   readOnly: true
        - name: log
          mountPath: /opt/tripbot/log

      # we use nginx as a proxy in front of the obs server
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
        volumeMounts:
        - mountPath: /etc/nginx # mount nginx-conf volumn to /etc/nginx
          readOnly: true
          name: nginx-conf
        - mountPath: /var/log/nginx
          name: log

      volumes:
      - name: dashcam-volume
        persistentVolumeClaim:
          claimName: dashcam-from-host-claim
      # - name: google-creds
      #   secret:
      #     secretName: google-creds
      - name: nginx-conf
        configMap:
          name: nginx-conf # place ConfigMap `nginx-conf` on /etc/nginx
          items:
            - key: nginx.conf
              path: nginx.conf
            - key: virtualhost.conf
              path: virtualhost/virtualhost.conf # dig directory
      - name: log
        emptyDir: {}
