_configuration.tpl 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. {{- define "invidious.configuration" -}}
  2. {{- $fullname := (include "ix.v1.common.lib.chart.names.fullname" $) -}}
  3. {{- $dbHost := (printf "%s-postgres" $fullname) -}}
  4. {{- $dbUser := "kemal" -}} {{/* User is hardcoded */}}
  5. {{- $dbName := "kemal" -}} {{/* Database is hardcoded */}}
  6. {{- $dbPass := (randAlphaNum 32) -}}
  7. {{- with (lookup "v1" "Secret" .Release.Namespace (printf "%s-postgres-creds" $fullname)) -}}
  8. {{- $dbPass = ((index .data "POSTGRES_PASSWORD") | b64dec) -}}
  9. {{- end -}}
  10. {{- $hmacKey := (randAlphaNum 64) -}}
  11. {{- with (lookup "v1" "Secret" .Release.Namespace (printf "%s-invidious-creds" $fullname)) -}}
  12. {{- $hmacKey = ((index .data "INVIDIOUS_HMAC_KEY") | b64dec) -}}
  13. {{- end -}}
  14. {{/* Temporary set dynamic db details on values,
  15. so we can print them on the notes */}}
  16. {{- $_ := set .Values "invidiousDbPass" $dbPass -}}
  17. {{- $_ := set .Values "invidiousDbHost" $dbHost -}}
  18. {{- $dbURL := (printf "postgres://%s:%s@%s:5432/%s?sslmode=disable" $dbUser $dbPass $dbHost $dbName) }}
  19. secret:
  20. postgres-creds:
  21. enabled: true
  22. data:
  23. POSTGRES_USER: {{ $dbUser }}
  24. POSTGRES_DB: {{ $dbName }}
  25. POSTGRES_PASSWORD: {{ $dbPass }}
  26. POSTGRES_HOST: {{ $dbHost }}
  27. POSTGRES_URL: {{ $dbURL }}
  28. # Used by invidious init script
  29. PGPASSWORD: {{ $dbPass }}
  30. PGHOST: {{ $dbHost }}
  31. PGPORT: "5432"
  32. {{/* Do not quote: bools, numbers, json */}}
  33. {{- $configOpts := list
  34. (dict "path" "check_tables" "value" "true")
  35. (dict "path" "database_url" "value" ($dbURL | quote))
  36. (dict "path" "db.user" "value" ($dbUser | quote))
  37. (dict "path" "db.password" "value" ($dbPass | quote))
  38. (dict "path" "db.dbname" "value" ($dbName | quote))
  39. (dict "path" "db.host" "value" ($dbHost | quote))
  40. (dict "path" "db.port" "value" "5432")
  41. (dict "path" "hmac_key" "value" ($hmacKey | quote))
  42. (dict "path" "host_binding" "value" ("0.0.0.0" | quote))
  43. (dict "path" "port" "value" .Values.invidiousNetwork.webPort)
  44. (dict "path" "admins" "value" (.Values.invidiousConfig.admins | toJson))
  45. (dict "path" "registration_enabled" "value" .Values.invidiousConfig.registrationEnabled)
  46. (dict "path" "login_enabled" "value" .Values.invidiousConfig.loginEnabled)
  47. (dict "path" "captcha_enabled" "value" .Values.invidiousConfig.captchaEnabled)
  48. }}
  49. invidious-creds:
  50. enabled: true
  51. data:
  52. INVIDIOUS_HMAC_KEY: {{ $hmacKey }}
  53. config.sh: |
  54. #!/bin/sh
  55. config="/config/config.yaml"
  56. echo "Updating Invidious Config..."
  57. {{- range $item := $configOpts }}
  58. echo "Updating [{{ $item.path }}]"
  59. yq -i '.{{ $item.path }} = {{ $item.value }}' "$config"
  60. echo "Updated [{{ $item.path }}] to $(yq '.{{ $item.path }}' "$config")"
  61. {{- end }}
  62. echo "Config updated!"
  63. {{- end -}}