Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.5KB

  1. defmodule Pleroma.Config.ReleaseRuntimeProvider do
  2. @moduledoc """
  3. Imports runtime config and `{env}.exported_from_db.secret.exs` for releases.
  4. """
  5. @behaviour Config.Provider
  6. @impl true
  7. def init(opts), do: opts
  8. @impl true
  9. def load(config, opts) do
  10. with_defaults = Config.Reader.merge(config, Pleroma.Config.Holder.release_defaults())
  11. config_path =
  12. opts[:config_path] || System.get_env("PLEROMA_CONFIG_PATH") || "/etc/pleroma/config.exs"
  13. with_runtime_config =
  14. if File.exists?(config_path) do
  15. runtime_config = Config.Reader.read!(config_path)
  16. with_defaults
  17. |> Config.Reader.merge(pleroma: [config_path: config_path])
  18. |> Config.Reader.merge(runtime_config)
  19. else
  20. warning = [
  21. IO.ANSI.red(),
  22. IO.ANSI.bright(),
  23. "!!! Config path is not declared! Please ensure it exists and that PLEROMA_CONFIG_PATH is unset or points to an existing file",
  24. IO.ANSI.reset()
  25. ]
  26. IO.puts(warning)
  27. with_defaults
  28. end
  29. exported_config_path =
  30. opts[:exported_config_path] ||
  31. config_path
  32. |> Path.dirname()
  33. |> Path.join("#{Pleroma.Config.get(:env)}.exported_from_db.secret.exs")
  34. with_exported =
  35. if File.exists?(exported_config_path) do
  36. exported_config = Config.Reader.read!(exported_config_path)
  37. Config.Reader.merge(with_runtime_config, exported_config)
  38. else
  39. with_runtime_config
  40. end
  41. with_exported
  42. end
  43. end