apiVersion: apps/v1
kind: Deployment
metadata:
  name: dawarich
  labels:
    app.kubernetes.io/controller: main
    app.kubernetes.io/instance: dawarich
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: dawarich
    helm.sh/chart: dawarich-5.0.1
  namespace: dawarich
spec:
  revisionHistoryLimit: 3
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app.kubernetes.io/controller: main
      app.kubernetes.io/name: dawarich
      app.kubernetes.io/instance: dawarich
  template:
    metadata:
      labels:
        app.kubernetes.io/controller: main
        app.kubernetes.io/instance: dawarich
        app.kubernetes.io/name: dawarich
    spec:
      enableServiceLinks: false
      serviceAccountName: dawarich
      automountServiceAccountToken: false
      hostIPC: false
      hostNetwork: false
      hostPID: false
      dnsPolicy: ClusterFirst
      containers:
        - args:
            - bin/rails
            - server
            - -p
            - "3000"
            - -b
            - '::'
          command:
            - web-entrypoint.sh
          env:
            - name: RAILS_ENV
              value: production
            - name: REDIS_URL
              value: redis://dawarich-valkey.dawarich:6379
            - name: DATABASE_HOST
              valueFrom:
                secretKeyRef:
                  key: host
                  name: dawarich-postgresql-18-cluster-app
            - name: DATABASE_PORT
              valueFrom:
                secretKeyRef:
                  key: port
                  name: dawarich-postgresql-18-cluster-app
            - name: DATABASE_USERNAME
              valueFrom:
                secretKeyRef:
                  key: user
                  name: dawarich-postgresql-18-cluster-app
            - name: DATABASE_PASSWORD
              valueFrom:
                secretKeyRef:
                  key: password
                  name: dawarich-postgresql-18-cluster-app
            - name: DATABASE_NAME
              valueFrom:
                secretKeyRef:
                  key: dbname
                  name: dawarich-postgresql-18-cluster-app
            - name: APPLICATION_HOSTS
              value: dawarich.alexlebens.net,dawarich.dawarich,localhost,::1,127.0.0.1
            - name: TIME_ZONE
              value: America/Chicago
            - name: APPLICATION_PROTOCOL
              value: http
            - name: OIDC_ISSUER
              value: https://authentik.alexlebens.net/application/o/darwich/
            - name: OIDC_REDIRECT_URI
              value: https://dawarich.alexlebens.net/users/auth/openid_connect/callback
            - name: OIDC_CLIENT_ID
              valueFrom:
                secretKeyRef:
                  key: client
                  name: dawarich-oidc-authentik
            - name: OIDC_CLIENT_SECRET
              valueFrom:
                secretKeyRef:
                  key: secret
                  name: dawarich-oidc-authentik
            - name: OIDC_PROVIDER_NAME
              value: Authentik
            - name: OIDC_AUTO_REGISTER
              value: "true"
            - name: PROMETHEUS_EXPORTER_ENABLED
              value: "true"
            - name: PROMETHEUS_EXPORTER_HOST
              value: 0.0.0.0
            - name: PROMETHEUS_EXPORTER_PORT
              value: "9394"
            - name: METRICS_USERNAME
              valueFrom:
                secretKeyRef:
                  key: user
                  name: dawarich-metrics-credentials
            - name: METRICS_PASSWORD
              valueFrom:
                secretKeyRef:
                  key: password
                  name: dawarich-metrics-credentials
            - name: SECRET_KEY_BASE
              valueFrom:
                secretKeyRef:
                  key: key
                  name: dawarich-key
            - name: OTP_ENCRYPTION_PRIMARY_KEY
              valueFrom:
                secretKeyRef:
                  key: otp-primary-key
                  name: dawarich-key
            - name: OTP_ENCRYPTION_DETERMINISTIC_KEY
              valueFrom:
                secretKeyRef:
                  key: otp-deterministic-key
                  name: dawarich-key
            - name: OTP_ENCRYPTION_KEY_DERIVATION_SALT
              valueFrom:
                secretKeyRef:
                  key: otp-derivation-salt
                  name: dawarich-key
            - name: RAILS_LOG_TO_STDOUT
              value: "true"
            - name: SELF_HOSTED
              value: "true"
            - name: STORE_GEODATA
              value: "true"
          image: freikin/dawarich:1.7.9@sha256:54329b050caab65f39367308ef7a9f2f3bd1fa3b6ba969d6a33bbf4a0f5e7e84
          livenessProbe:
            exec:
              command:
                - /bin/sh
                - -c
                - wget -qO - http://127.0.0.1:3000/api/v1/health | grep -q '"status"\s*:\s*"ok"'
            failureThreshold: 5
            initialDelaySeconds: 60
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 10
          name: main
          resources:
            requests:
              cpu: 20m
              memory: 750Mi
          volumeMounts:
            - mountPath: /var/app/public
              name: public
            - mountPath: /var/app/storage
              name: storage
            - mountPath: /var/app/tmp/imports/watched
              name: watched
        - args:
            - sidekiq
          command:
            - sidekiq-entrypoint.sh
          env:
            - name: RAILS_ENV
              value: production
            - name: REDIS_URL
              value: redis://dawarich-valkey.dawarich:6379
            - name: DATABASE_HOST
              valueFrom:
                secretKeyRef:
                  key: host
                  name: dawarich-postgresql-18-cluster-app
            - name: DATABASE_PORT
              valueFrom:
                secretKeyRef:
                  key: port
                  name: dawarich-postgresql-18-cluster-app
            - name: DATABASE_USERNAME
              valueFrom:
                secretKeyRef:
                  key: user
                  name: dawarich-postgresql-18-cluster-app
            - name: DATABASE_PASSWORD
              valueFrom:
                secretKeyRef:
                  key: password
                  name: dawarich-postgresql-18-cluster-app
            - name: DATABASE_NAME
              valueFrom:
                secretKeyRef:
                  key: dbname
                  name: dawarich-postgresql-18-cluster-app
            - name: APPLICATION_HOSTS
              value: dawarich.alexlebens.net,dawarich.dawarich,localhost,::1,127.0.0.1
            - name: TIME_ZONE
              value: America/Chicago
            - name: APPLICATION_PROTOCOL
              value: http
            - name: DISTANCE_UNIT
              value: mi
            - name: OIDC_ISSUER
              value: https://authentik.alexlebens.net/application/o/darwich/
            - name: OIDC_REDIRECT_URI
              value: https://dawarich.alexlebens.net/users/auth/openid_connect/callback
            - name: OIDC_CLIENT_ID
              valueFrom:
                secretKeyRef:
                  key: client
                  name: dawarich-oidc-authentik
            - name: OIDC_CLIENT_SECRET
              valueFrom:
                secretKeyRef:
                  key: secret
                  name: dawarich-oidc-authentik
            - name: OIDC_PROVIDER_NAME
              value: Authentik
            - name: OIDC_AUTO_REGISTER
              value: "true"
            - name: PROMETHEUS_EXPORTER_ENABLED
              value: "true"
            - name: PROMETHEUS_EXPORTER_HOST
              value: 0.0.0.0
            - name: PROMETHEUS_EXPORTER_PORT
              value: "9394"
            - name: METRICS_USERNAME
              valueFrom:
                secretKeyRef:
                  key: user
                  name: dawarich-metrics-credentials
            - name: METRICS_PASSWORD
              valueFrom:
                secretKeyRef:
                  key: password
                  name: dawarich-metrics-credentials
            - name: SECRET_KEY_BASE
              valueFrom:
                secretKeyRef:
                  key: key
                  name: dawarich-key
            - name: OTP_ENCRYPTION_PRIMARY_KEY
              valueFrom:
                secretKeyRef:
                  key: otp-primary-key
                  name: dawarich-key
            - name: OTP_ENCRYPTION_DETERMINISTIC_KEY
              valueFrom:
                secretKeyRef:
                  key: otp-deterministic-key
                  name: dawarich-key
            - name: OTP_ENCRYPTION_KEY_DERIVATION_SALT
              valueFrom:
                secretKeyRef:
                  key: otp-derivation-salt
                  name: dawarich-key
            - name: RAILS_LOG_TO_STDOUT
              value: "true"
            - name: SELF_HOSTED
              value: "true"
            - name: STORE_GEODATA
              value: "true"
          image: freikin/dawarich:1.7.9@sha256:54329b050caab65f39367308ef7a9f2f3bd1fa3b6ba969d6a33bbf4a0f5e7e84
          livenessProbe:
            exec:
              command:
                - pgrep
                - -f
                - sidekiq
            failureThreshold: 5
            initialDelaySeconds: 60
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 10
          name: sidekiq
          volumeMounts:
            - mountPath: /var/app/public
              name: public
            - mountPath: /var/app/storage
              name: storage
            - mountPath: /var/app/tmp/imports/watched
              name: watched
      volumes:
        - name: public
          persistentVolumeClaim:
            claimName: dawarich-public
        - name: storage
          persistentVolumeClaim:
            claimName: dawarich-storage
        - name: watched
          persistentVolumeClaim:
            claimName: dawarich-watched
